//### This file created by BYACC 1.8(/Java extension  1.15)
//### Java capabilities added 7 Jan 97, Bob Jamison
//### Updated : 27 Nov 97  -- Bob Jamison, Joe Nieten
//###           01 Jan 98  -- Bob Jamison -- fixed generic semantic constructor
//###           01 Jun 99  -- Bob Jamison -- added Runnable support
//###           06 Aug 00  -- Bob Jamison -- made state variables class-global
//###           03 Jan 01  -- Bob Jamison -- improved flags, tracing
//###           16 May 01  -- Bob Jamison -- added custom stack sizing
//###           04 Mar 02  -- Yuval Oren  -- improved java performance, added options
//###           14 Mar 02  -- Tomas Hurka -- -d support, static initializer workaround
//### Please send bug reports to tom@hukatronic.cz
//### static char yysccsid[] = "@(#)yaccpar	1.8 (Berkeley) 01/20/90";



package upbeat.frontend;



//#line 2 "upbeat-a.yacc"
 /* import java.long.Math;
  import java.util.StringTokenizer; */
import java.io.*;
import java.util.Enumeration;
import java.util.Hashtable;	/* Used by the symbol table*/
import java.util.LinkedList; /* Used to create phrases*/
import java.util.Iterator; /* Used to iterate over lists*/

import upbeat.frontend.upbeatVal;
  
  class upbeatVal {
	  public String code;
	  
	  public int numMusicians;
	  
	  public enum Type { ubVOID, ubINT, ubFLOAT, ubBOOL, ubCUE, ubPHRASE, ubTIME, ubSTRING };
	  public Type type;
	  
	  public enum UnaryOp { uopPLUS, uopMINUS, uopNOT };
	  public UnaryOp unaryOp;
	  
	  public enum ToBy { To, By };
	  public ToBy toOrBy;
	  
	  public enum ChangeParam { Volume, Pitch, Instrument };
	  public ChangeParam changeParam;
	  
	  public LinkedList<String> listval;
	  
	  /* This is used to list the types in the parameter list of functions*/
	  public LinkedList< upbeatVal.Type > listTypes;
	  public LinkedList< String > listExprs;
	  
	  /* We were running into problems because we check to see if functions are defined at a different*/
	  /* place as regular identifiers.  As a result, I had to move the check to see whether an identifier*/
	  /* exists up a bit higher in the grammar.  As a result, we now have this value that tells whether*/
	  /* or not we need to do a definition check.*/
	  public boolean definitionCheck;
	  
	  public int ival;
	  public double dval;
	  public boolean bval;
	  public String sval;
	  public Object obj;
	  
	  /* These are used in range expressions.  rangeLeft and rangeRight*/
	  /* are the strings corresponding with the expressions, and*/
	  /* leftOpen and rightOpen tell whether the interval is open on the*/
	  /* left and right*/
	  public String rangeLeft;
	  public boolean leftOpen;
	  public Type rangeLeftType;
	  public String rangeRight;
	  public boolean rightOpen;
	  public Type rangeRightType;
	  
	  /* This is used in the postfix_expression productions*/
	  /* so we can signal errors when the Upbeat programmer*/
	  /* writes something like:*/
	  /* Foo()()();*/
	  public boolean alreadyPostFixed;
	  
	  public boolean assignable;

	  public upbeatVal() { }
	  
	  public upbeatVal( ToBy t ) { toOrBy = t; }
	  
	  public upbeatVal( ChangeParam p ) { changeParam = p; }

	  public upbeatVal(int val) { ival=val; }

	  public upbeatVal(double val) { dval=val; }
	  
	  public upbeatVal(boolean val) { bval=val; }

	  public upbeatVal(String val) { code=val; }

	  public upbeatVal(Object val) { obj=val; }
	  
	  public upbeatVal(Type val) { type =val; }
	  
	  public upbeatVal(upbeatVal val) {
		  code = val.code;
		  numMusicians = val.numMusicians;
		  type = val.type;
		  toOrBy = val.toOrBy;
		  changeParam = val.changeParam;
		  ival = val.ival;
		  dval = val.dval;
		  sval = val.sval;
		  obj = val.obj;
	  }
	  
	  public upbeatVal clone() {
		  return new upbeatVal(this);
	  }
  }
  
  class FunctionType {
	  private LinkedList< upbeatVal.Type > mArgTypes;
	  private upbeatVal.Type mReturnType;
	  
	  public FunctionType() {
		  mArgTypes = new LinkedList< upbeatVal.Type >();
		  mReturnType = null;
	  }
	  
	  public void SetReturnType( upbeatVal.Type t ) {
		  mReturnType = t;
	  }
	  
	  public void SetArgs( LinkedList< upbeatVal.Type > args ) {
		  mArgTypes = args;
	  }
	  
	  public void AddArg( upbeatVal.Type arg ) {
		  mArgTypes.add( arg );
	  }
	  
	  public upbeatVal.Type GetReturnType() {
		  return mReturnType;
	  }
	  
	  public LinkedList< upbeatVal.Type > GetArgs() {
		  return mArgTypes;
	  }
	  
	  public boolean CheckArgTypes( LinkedList< upbeatVal.Type > args ){
		  Iterator< upbeatVal.Type > argIter = args.iterator();
		  Iterator< upbeatVal.Type > mArgIter = mArgTypes.iterator();
		  
		  /* If either of the types don't match up, return false*/
		  while( argIter.hasNext() && mArgIter.hasNext() ) {
		      if( argIter.next() != mArgIter.next() )
		    	  return false;
		  }
		      
		  /* If the number of arguments doesn't match up, return false*/
		  if( argIter.hasNext() || mArgIter.hasNext() )
			  return false;
		  
		  return true;
	  }
  }
  
  /* Pretty simple symbol table.  Can be expanded if need be*/
  class SymbolTable {
	  private Hashtable< String, upbeatVal.Type > mSymbols;
	  private Hashtable< String, Integer > mDefLine;
	  
	  private Hashtable< String, FunctionType > mFuncSymbols;
	  private Hashtable< String, Integer > mFuncDefLine;
	  
	  public SymbolTable parent;
	  
	  public boolean inConductor;
	  public boolean inConductorFunc;
	  public boolean inMusician;
	  public boolean inCueResponse;
	  public boolean inRepeat;
	  
	  /* This is the name of the function we are in, if it exists...*/
	  public String myName;
	  public boolean returns;
	  
	  SymbolTable() {
		  /* special top-level symbol table*/
		  parent = null;
		  inConductor = false;
		  inConductorFunc = false;
		  inMusician = false;
		  inCueResponse = false;
		  inRepeat = false;
		  myName = null;
		  mSymbols = new Hashtable<String, upbeatVal.Type>();
		  mDefLine = new Hashtable<String, Integer>();
		  mFuncSymbols = new Hashtable< String, FunctionType >();
		  mFuncDefLine = new Hashtable< String, Integer >();
	  }
	  SymbolTable(SymbolTable p) {
		  parent = p;
		  inConductorFunc = p.inConductorFunc;
		  inConductor = p.inConductor;
		  inMusician = p.inMusician;
		  inCueResponse = p.inCueResponse;
		  inRepeat = p.inRepeat;
		  myName = p.myName;
		  mSymbols = new Hashtable<String, upbeatVal.Type>();
		  mDefLine = new Hashtable<String, Integer>();
		  mFuncSymbols = new Hashtable< String, FunctionType >();
		  mFuncDefLine = new Hashtable< String, Integer >();
	  }
	  
	  public void Returns() {
		  SymbolTable i = this;
		  
		  while( i.inConductorFunc && i.myName != null && i != null) {
			  i.returns = true;
			  i = i.parent;
		  }
		  
		  if( i.inConductorFunc || i.myName != null || i == null ) {
			  throw new Error( "Cannot figure out which function we are returning from" );
		  }
	  }
	  
	  public upbeatVal.Type GetCurrentReturnType() {
		  return GetFuncReturnType( myName );
	  }
	  
	  public void AddSymbol( String name, upbeatVal.Type type, int line ) {
		  mSymbols.put( name, type );
		  mDefLine.put( name, line );
	  }
	  
	  public void AddFuncSymbol( String name, FunctionType type, int line ) {
		  mFuncSymbols.put( name, type );
		  mFuncDefLine.put( name, line );
	  }
	  
	  public int numSymbols() {
		  if(parent != null) {
			  return mSymbols.size() + parent.numSymbols();
		  }
		  return mSymbols.size();
	  }
	  
	  public int numFuncSymbols() {
		  if(parent != null) {
			  return mFuncSymbols.size() + parent.numFuncSymbols();
		  }
		  return mFuncSymbols.size();
	  }
	  
	  /* returns null if the name does not exist!*/
	  public upbeatVal.Type GetType( String name ) {
		  SymbolTable i = this;
		  while (i != null && i.mSymbols.get(name) == null) {
			  i = i.parent;
		  }
		  if (i==null) {
			  /* no symbol by that name.*/
			  return null;
		  }
		  return i.mSymbols.get( name );
	  }
	  
	  /* returns null if the name does not exist!*/
	  public upbeatVal.Type GetFuncReturnType( String name ) {
		  SymbolTable i = this;
		  while (i != null && i.mFuncSymbols.get(name) == null) {
			  i = i.parent;
		  }
		  if (i==null) {
			  /* no symbol by that name.*/
			  return null;
		  }
		  return i.mFuncSymbols.get( name ).GetReturnType();
	  }
	  
	  public boolean CheckFuncArgTypes( String name,  LinkedList< upbeatVal.Type > argTypes ) {
		  SymbolTable i = this;
		  while (i != null && i.mFuncSymbols.get(name) == null) {
			  i = i.parent;
		  }
		  if (i==null) {
			  /* no symbol by that name.*/
			  return false;
		  }
		  return i.mFuncSymbols.get( name ).CheckArgTypes( argTypes );
	  }
	  
	  public LinkedList< upbeatVal.Type > GetParamTypes( String name ) {
		  SymbolTable i = this;
		  while (i != null && i.mFuncSymbols.get(name) == null) {
			  i = i.parent;
		  }
		  if (i==null) {
			  /* no symbol by that name.*/
			  return null;
		  }
		  return i.mFuncSymbols.get( name ).GetArgs();
	  }
	  
	  public int GetDefLine( String name ) {
		  SymbolTable i = this;
		  while (i != null && i.mDefLine.get(name) == null) {
			  i = i.parent;
		  }
		  if (i==null) {
			  /* no symbol by that name.*/
			  return -1;
		  }
		  return i.mDefLine.get( name ); 
	  }
	  
	  public int GetFuncDefLine( String name ) {
		  SymbolTable i = this;
		  while (i != null && i.mFuncDefLine.get(name) == null) {
			  i = i.parent;
		  }
		  if (i==null) {
			  /* no symbol by that name.*/
			  return -1;
		  }
		  return i.mFuncDefLine.get( name ); 
	  }
	  
	  public String toString() {
		  String blah = new String();
		  Enumeration<String> keys = mSymbols.keys();
		  while(keys != null && keys.hasMoreElements()) {
			  String k = keys.nextElement();
			  blah = blah + "Var: " + k + " Type: " + mSymbols.get(k) + "\n";
		  }
		  return blah;
	  }
  }
//#line 337 "parser.java"




public class parser
{

boolean yydebug;        //do I want debug output?
int yynerrs;            //number of errors so far
int yyerrflag;          //was there an error?
int yychar;             //the current working character

//########## MESSAGES ##########
//###############################################################
// method: debug
//###############################################################
void debug(String msg)
{
  if (yydebug)
    System.out.println(msg);
}

//########## STATE STACK ##########
final static int YYSTACKSIZE = 500;  //maximum stack size
int statestk[] = new int[YYSTACKSIZE]; //state stack
int stateptr;
int stateptrmax;                     //highest index of stackptr
int statemax;                        //state when highest index reached
//###############################################################
// methods: state stack push,pop,drop,peek
//###############################################################
final void state_push(int state)
{
  try {
		stateptr++;
		statestk[stateptr]=state;
	 }
	 catch (ArrayIndexOutOfBoundsException e) {
     int oldsize = statestk.length;
     int newsize = oldsize * 2;
     int[] newstack = new int[newsize];
     System.arraycopy(statestk,0,newstack,0,oldsize);
     statestk = newstack;
     statestk[stateptr]=state;
  }
}
final int state_pop()
{
  return statestk[stateptr--];
}
final void state_drop(int cnt)
{
  stateptr -= cnt; 
}
final int state_peek(int relative)
{
  return statestk[stateptr-relative];
}
//###############################################################
// method: init_stacks : allocate and prepare stacks
//###############################################################
final boolean init_stacks()
{
  stateptr = -1;
  val_init();
  return true;
}
//###############################################################
// method: dump_stacks : show n levels of the stacks
//###############################################################
void dump_stacks(int count)
{
int i;
  System.out.println("=index==state====value=     s:"+stateptr+"  v:"+valptr);
  for (i=0;i<count;i++)
    System.out.println(" "+i+"    "+statestk[i]+"      "+valstk[i]);
  System.out.println("======================");
}


//########## SEMANTIC VALUES ##########
//## **user defined:upbeatVal
String   yytext;//user variable to return contextual strings
upbeatVal yyval; //used to return semantic vals from action routines
upbeatVal yylval;//the 'lval' (result) I got from yylex()
upbeatVal valstk[] = new upbeatVal[YYSTACKSIZE];
int valptr;
//###############################################################
// methods: value stack push,pop,drop,peek.
//###############################################################
final void val_init()
{
  yyval=new upbeatVal();
  yylval=new upbeatVal();
  valptr=-1;
}
final void val_push(upbeatVal val)
{
  try {
    valptr++;
    valstk[valptr]=val;
  }
  catch (ArrayIndexOutOfBoundsException e) {
    int oldsize = valstk.length;
    int newsize = oldsize*2;
    upbeatVal[] newstack = new upbeatVal[newsize];
    System.arraycopy(valstk,0,newstack,0,oldsize);
    valstk = newstack;
    valstk[valptr]=val;
  }
}
final upbeatVal val_pop()
{
  return valstk[valptr--];
}
final void val_drop(int cnt)
{
  valptr -= cnt;
}
final upbeatVal val_peek(int relative)
{
  return valstk[valptr-relative];
}
final upbeatVal dup_yyval(upbeatVal val)
{
  return val;
}
//#### end semantic value section ####
public final static short IDENTIFIER=257;
public final static short CONSTANT=258;
public final static short STRING_LITERAL=259;
public final static short EQ_ASS=260;
public final static short AND_OP=261;
public final static short OR_OP=262;
public final static short EQ_OP=263;
public final static short NE_OP=264;
public final static short LE_OP=265;
public final static short GE_OP=266;
public final static short LESS_OP=267;
public final static short GREAT_OP=268;
public final static short INT=269;
public final static short FLOAT=270;
public final static short BOOL=271;
public final static short CUE=272;
public final static short PHRASE=273;
public final static short TIME=274;
public final static short INPUT=275;
public final static short CURR_CUE=276;
public final static short CURRENT_VALUE=277;
public final static short DATA=278;
public final static short MORE=279;
public final static short VALUE_AT=280;
public final static short CASE=281;
public final static short RETURN=282;
public final static short REPEAT=283;
public final static short BREAK=284;
public final static short CONTINUE=285;
public final static short TIME_SIGNATURE=286;
public final static short TEMPO=287;
public final static short ADD=288;
public final static short CONDUCTOR=289;
public final static short MUSICIAN=290;
public final static short IN=291;
public final static short CHANGE=292;
public final static short VOLUME=293;
public final static short INSTRUMENT=294;
public final static short PITCH=295;
public final static short TO=296;
public final static short BY=297;
public final static short DB=298;
public final static short RRPT=299;
public final static short YYERRCODE=256;
final static short yylhs[] = {                           -1,
    0,    1,    1,    4,    5,    7,    2,    2,    6,    6,
    6,    6,    6,    6,   11,   11,   12,   11,    9,    9,
   13,   13,   13,   13,   13,   13,   17,   17,   17,   17,
   17,   21,   22,   20,   20,   14,   14,   24,   18,   27,
   18,   25,   25,   26,   28,   19,   23,   23,   31,   29,
   29,   32,   32,   33,   33,   33,   34,   34,   34,   34,
   34,   35,   35,   37,   37,   37,   37,   36,   36,   36,
   38,   38,   38,   38,   39,   39,   39,   30,   30,   30,
   30,   30,   43,   43,   43,   42,   42,   42,   42,   42,
   42,   40,   40,   40,   44,   44,   45,   45,   10,   10,
   46,   47,   47,   41,   41,   41,   41,   41,   41,    8,
    8,   49,   48,   50,   51,   48,   52,   48,   53,   54,
   48,   15,   16,   16,   56,   57,   57,   57,   58,   58,
   55,   59,   59,   61,   61,   62,   60,   60,   60,   63,
   63,   63,   63,   64,   64,   65,    3,    3,   68,   66,
   67,   67,   67,   67,   69,   69,   71,   70,
};
final static short yylen[] = {                            2,
    3,    2,    2,    5,    3,    0,    5,    2,    1,    2,
    2,    3,    2,    2,    2,    3,    0,    5,    1,    2,
    1,    1,    1,    1,    1,    2,    1,    1,    1,    1,
    1,    2,    2,    2,    3,    2,    1,    0,    5,    0,
    3,    1,    2,    4,    0,    6,    1,    3,    1,    1,
    3,    1,    3,    1,    3,    3,    1,    3,    3,    3,
    3,    1,    3,    5,    5,    5,    5,    1,    3,    3,
    1,    3,    3,    3,    1,    2,    4,    1,    1,    3,
    4,    3,    6,    3,    3,    1,    1,    1,    1,    3,
    2,    1,    1,    1,    1,    3,    1,    3,    2,    3,
    2,    1,    3,    1,    1,    1,    1,    1,    1,    1,
    2,    0,    5,    0,    0,    7,    0,    6,    0,    0,
    8,    4,    2,    2,    4,    1,    1,    1,    1,    1,
    2,    1,    1,    4,    5,    3,    2,    2,    0,    1,
    3,    1,    3,    3,    4,    2,    1,    2,    0,    6,
    2,    2,    3,    2,    1,    2,    0,    3,
};
final static short yydefred[] = {                         0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    2,    3,    0,    5,    8,    6,    0,    0,  147,
    0,    0,    0,  148,    4,    0,    0,   88,   89,   92,
   93,  104,  105,  106,  107,  108,  109,    0,   87,    0,
    0,    0,    0,    0,    0,    0,    0,   37,    0,    0,
   94,    0,    0,    0,    0,   21,   19,   22,   23,   24,
   25,   27,   28,   29,   30,   31,    0,    0,    0,    0,
    0,    0,   57,    0,    0,   71,    0,    0,   78,   79,
    0,  110,    0,    0,    0,  132,  133,  149,   14,   26,
   13,   91,    0,    0,    0,    0,    0,   86,   34,    0,
    0,   33,   32,    0,  126,  127,  128,    0,    0,    0,
    0,    0,    0,   15,    0,    0,    0,    0,    7,    0,
    0,  111,    0,   20,    0,    0,    0,   36,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,   76,    0,  101,   99,
  123,  124,    0,  131,    0,    0,    0,    0,  112,    0,
   84,   85,    0,    0,    0,   41,   35,    0,    0,  129,
  130,    0,    0,    0,    0,  136,   16,    0,    0,   90,
    0,    0,    0,  100,    0,   48,   80,   95,    0,   82,
    0,    0,    0,   60,   61,   58,   59,    0,    0,    0,
    0,   63,   74,   72,   73,    0,    0,    0,  146,  137,
  138,    0,    0,    0,    0,    0,   97,    0,    0,    0,
    0,   45,  122,  125,  141,  143,    0,    0,    0,   77,
   81,    0,    0,    0,  103,  117,    0,    0,    0,  151,
    0,    0,  152,  150,  113,  115,    0,    0,   39,   43,
    0,    0,    0,  135,   18,   96,    0,    0,    0,    0,
  145,    0,  157,  156,  153,    0,   98,   83,   44,   46,
    0,    0,  118,  120,  158,  116,   64,   66,   65,   67,
    0,  121,
};
final static short yydgoto[] = {                          3,
    4,   11,   19,    5,    6,   52,   22,   53,   54,   55,
   56,  116,   57,   58,   59,   60,   61,   62,   63,   64,
   65,   66,   67,   95,  219,  220,   96,  252,   68,   69,
  254,   70,   71,   72,   73,   74,  202,   75,   76,   77,
  179,   79,   80,  189,  216,   81,  149,   82,  215,  160,
  266,  259,  237,  281,   83,   84,  108,  172,   85,  154,
   86,   87,  155,  156,  157,   20,  214,  158,  240,  241,
  262,
};
final static short yysindex[] = {                      -231,
 -219, -217,    0, -220, -244, -238,   36,   32,  -24,  -19,
 -183,    0,    0, -146,    0,    0,    0, -142, -183,    0,
   63,  -33,   43,    0,    0,  -28,   85,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,  100,    0,    0,
  805,  138,  120,  121,  997, -165,  -47,    0,  122,  722,
    0,   57, -101,    4,    4,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,  137,  -65,  -31,  -63,
 -185, -132,    0,  -37,   17,    0,  997,  -58,    0,    0,
  141,    0,  146,  147,  -42,    0,    0,    0,    0,    0,
    0,    0,  166, -181,   86,  168,  173,    0,    0,  158,
  997,    0,    0,  997,    0,    0,    0, -182,   96,   98,
 -148,  -79,   -9,    0,  143,  -80,  186,  187,    0,   85,
  -25,    0, -101,    0, -101,    4,  174,    0,  997,  997,
  841,  -44,  997,  997,  997,  997,  997,  997,  997,  997,
  997,  -18,  997,  997,  997,    6,    0,  -39,    0,    0,
    0,    0, -148,    0,  -45,  -42,  -42,   41,    0,  -80,
    0,    0,  195,  168,  997,    0,    0,  205,  197,    0,
    0,  997, -148, -148,  -41,    0,    0,   41,    7,    0,
  997,  217, -101,    0,  -63,    0,    0,    0,   27,    0,
 -185, -132, -132,    0,    0,    0,    0,   17,   17,  997,
  997,    0,    0,    0,    0,  997,  226,  -27,    0,    0,
    0,  298,   78,  156,  148,   31,    0,  997,  157,  168,
  243,    0,    0,    0,    0,    0,  997,  250,   58,    0,
    0,  997,  247,  257,    0,    0,  -80,  997,    0,    0,
   35,  298,    0,    0,    0,    0,  -80,  278,    0,    0,
  349,  349,  -65,    0,    0,    0,  997,  997,  148,   44,
    0,  148,    0,    0,    0,  148,    0,    0,    0,    0,
  -17,  -16,    0,    0,    0,    0,    0,    0,    0,    0,
  148,    0,
};
final static short yyrindex[] = {                         0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,  320,    0,
    0,    0,    0,    0,    0,    0,  477,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,  -21,
    0,    0,    0,    0,    0,    0,    0,    0,   34,    0,
    0,    0,  196,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,  796,  437,  967,
  897,  713,    0,  595,  458,    0,    0,    0,    0,    0,
    0,    0,    0,    0,  268,    0,    0,    0,    0,    0,
    0,    0,  114,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0, -179, -150,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,  203,    0,  207,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,  401,    0,  120,    0,    0,
    0,    0,    0,    0,    0,  268,  268,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,  215,    0,  976,    0,    0,    0,    0,    0,
  906,  832,  874,    0,    0,    0,    0,  519,  558,    0,
    0,    0,    0,    0,    0,    0,  180,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,  219,
    0,    0,    0,    0,    0,    0,   92,    0,    1,    0,
    0,    0,    0,    0,    0,    0,    0,   95,  638,    0,
  220,  221,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,  -54,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,
};
final static short yygindex[] = {                         0,
    0,    0,    0,  324,  337,    0,    0,  -34,  -26,  -88,
 -201,    0,  932,    0,    0,    0,    0,    0,    0,    0,
    0,    0,   12,    0,  135,  260,    0,    0, -187, 1063,
  126,  229,  232,   23,    2,    0,    0,   19,  -50,    0,
  -20,    0,    0,    0,  130,  -52,    0,  -36,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,   18,
    0,    0,  -29,    0,    0,  350,    0,    0, -175,    0,
    0,
};
final static int YYTABLESIZE=1301;
static short yytable[];
static { yytable();}
static void yytable(){
yytable = new short[]{                         51,
  207,   78,  127,   49,   49,  140,   50,  141,  131,   30,
  111,   31,   92,  245,  132,  153,  122,  112,   40,  123,
  125,  200,  115,  277,  279,   48,  147,  178,  126,  118,
   90,   92,  121,  121,   78,    9,   51,  243,    7,  253,
    8,  102,    2,   50,  102,  131,   30,    1,   31,   90,
  253,  132,  100,  143,    1,    2,  104,  273,  144,  102,
  275,  117,   48,  145,  276,  264,  265,  231,   10,  213,
  232,  246,  201,   51,  247,  278,  280,  134,  135,  282,
   50,  175,   14,   30,  274,   31,  122,  247,  122,   49,
   15,  183,  203,  204,  205,  161,   91,  162,  163,   48,
   16,   38,  121,   17,  121,  121,   18,  217,  109,  110,
   51,   21,  168,  170,  171,  169,   23,   50,  140,  140,
   30,   25,   31,  208,   93,  127,   49,  105,  106,  107,
  230,  212,  136,  137,  138,  139,   48,  194,  195,  196,
  197,  186,  188,  225,  226,   94,  122,  142,  142,  134,
  134,  228,  144,  144,   51,  120,  192,  193,  198,  199,
  127,   50,  121,   49,   30,   88,   31,   32,   33,   34,
   35,   36,   37,  210,  211,   51,  221,  101,  102,  103,
   48,  119,   50,  224,  217,   30,  242,   31,   32,   33,
   34,   35,   36,   37,  267,  128,  129,  133,  148,  150,
   49,   48,   49,   49,  151,  152,  159,  165,  164,  109,
  110,  233,  234,   92,  109,  110,  167,  235,  176,  173,
  206,  174,   26,   27,   28,   29,  180,  181,  130,  248,
   89,  182,  184,  190,  218,   32,   33,   34,   35,   36,
   37,   38,   39,  256,   49,  222,  114,   40,   41,   42,
   43,   44,  209,  142,   45,  223,  207,  227,   46,  113,
   27,   28,   29,  229,   47,   49,  236,  177,  271,  272,
   49,  238,   32,   33,   34,   35,   36,   37,   38,   39,
  244,  249,   51,  251,   40,   41,   42,   43,   44,   50,
  257,   45,   30,  263,   31,   46,  113,   98,   28,   29,
  258,   47,   17,   17,   17,   17,   17,   17,   48,   32,
   33,   34,   35,   36,   37,   38,   39,  206,  268,    1,
    9,   40,   41,   42,   43,   44,  139,   10,   45,   13,
   51,   11,   46,  113,   98,   28,  239,   50,   47,   12,
   30,   12,   31,   42,  155,  154,   32,   33,   34,   35,
   36,   37,   38,   39,  250,  166,   48,  185,   40,   41,
   42,   43,   44,  261,  191,   45,  260,    0,   24,   46,
    0,    0,   49,    0,  255,   47,    0,  113,   98,   28,
   29,   51,  114,  114,  114,  114,  114,  114,   50,    0,
    0,   30,    0,   31,    0,    0,   38,   39,  113,   98,
   28,   29,   40,   41,   42,   43,   44,   48,    0,   45,
    0,    0,    0,   46,    0,    0,    0,   38,   39,   47,
   49,    0,    0,   40,   41,   42,   43,   44,    0,    0,
   45,    0,    0,   75,   46,    0,    0,   75,    0,    0,
   47,   75,   75,   75,   75,   75,    0,   75,  119,  119,
  119,  119,  119,  119,    0,    0,    0,    0,   75,   75,
    0,    0,    0,    0,    0,    0,    0,    0,    0,   75,
    0,   49,    0,   75,    0,    0,    0,   75,   75,   75,
   75,   75,    0,   75,    0,    0,    0,    0,    0,    0,
   68,    0,    0,   75,    0,   75,    0,   68,   68,    0,
   68,   68,   68,    0,    0,  113,   98,   28,   29,    0,
    0,    0,    0,   86,    0,   68,   68,    0,   86,   86,
    0,   86,   86,   86,   38,   39,    0,    0,    0,   75,
   40,   41,   42,   43,   44,   86,    0,   45,    0,    0,
    0,   46,    0,    0,    0,    0,    0,   47,    0,    0,
   68,   69,    0,  113,   98,   28,  239,    0,   69,   69,
    0,   69,   69,   69,    0,    0,    0,    0,    0,    0,
    0,    0,   38,   39,    0,    0,   69,   69,   40,   41,
   42,   43,   44,    0,    0,   45,    0,    0,    0,   46,
   70,    0,    0,    0,    0,   47,    0,   70,   70,    0,
   70,   70,   70,    0,  113,   98,   28,   29,    0,    0,
    0,   69,    0,    0,    0,   70,   70,    0,    0,    0,
    0,    0,    0,   38,   39,    0,    0,   62,    0,   40,
   41,   42,   43,   44,   62,   62,   45,    0,   62,    0,
   46,    0,    0,    0,    0,    0,   47,    0,    0,    0,
   70,    0,   62,   62,    0,    0,   75,   75,   75,   75,
    0,   75,   75,   75,   75,   75,   75,   75,   75,    0,
    0,    0,    0,    0,   89,   75,   75,   89,    0,   89,
   89,    0,   89,   89,   89,    0,    0,   62,    0,    0,
    0,   75,   75,   75,   75,   75,   89,   75,   75,   75,
   75,   75,   75,   75,   75,    0,    0,    0,    0,    0,
    0,   75,   75,   68,   68,   68,   68,    0,   68,   68,
   68,   68,   68,   68,   68,   68,    0,   75,    0,    0,
    0,    0,   68,   68,    0,    0,   86,   86,   86,   86,
   86,   86,   86,   86,   86,   54,    0,    0,   68,    0,
    0,    0,   54,   54,   51,   54,   54,   54,    0,    0,
  157,   50,    0,    0,   30,    0,   31,   86,    0,    0,
   54,   54,    0,    0,   69,   69,   69,   69,    0,   69,
   69,   69,   69,   69,   69,   69,   69,    0,    0,    0,
    0,    0,    0,   69,   69,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,   54,    0,    0,    0,   69,
    0,    0,    0,   70,   70,   70,   70,    0,   70,   70,
   70,   70,   70,   70,   70,   70,    0,    0,   47,    0,
    0,    0,   70,   70,    0,   47,   47,   51,   47,   47,
   47,    0,    0,    0,   50,    0,    0,   30,   70,   31,
   62,   62,   62,   62,   47,   62,   62,   62,   62,   62,
   62,   62,   62,   99,   55,    0,    0,    0,    0,   62,
   62,   55,   55,   51,   55,   55,   55,    0,    0,    0,
   50,  187,    0,   30,    0,   31,    0,    0,   47,   55,
   55,    0,    0,    0,    0,    0,    0,   89,   89,   89,
   89,   89,   89,   89,   89,   89,   56,    0,    0,    0,
    0,    0,    0,   56,   56,    0,   56,   56,   56,    0,
    0,    0,    0,    0,   55,    0,    0,    0,   89,   52,
    0,   56,   56,    0,    0,    0,   52,   52,   53,   52,
   52,   52,    0,    0,    0,   53,   53,    0,   53,   53,
   53,    0,    0,    0,   52,   52,    0,    0,    0,    0,
    0,    0,    0,   53,   53,    0,   56,    0,   54,   54,
   54,   54,    0,   54,   54,   54,   54,   97,   98,   28,
   29,    0,    0,    0,    0,  124,    0,   54,   54,   52,
   32,   33,   34,   35,   36,   37,   38,   39,   53,   50,
    0,    0,    0,    0,    0,    0,   50,   50,   51,   50,
   50,   50,    0,    0,    0,   51,   51,    0,   51,   51,
   51,    0,    0,    0,   50,   50,    0,    0,    0,   51,
    0,    0,    0,   51,   51,    0,   50,    0,    0,   30,
    0,   31,    0,    0,    0,    0,  124,    0,    0,    0,
    0,   47,   47,   47,   47,    0,    0,  124,    0,   50,
   97,   98,   28,   29,    0,    0,    0,    0,   51,    0,
   47,   47,    0,    0,    0,    0,    0,    0,    0,   38,
   39,    0,    0,    0,    0,    0,    0,   55,   55,   55,
   55,    0,   55,   55,   55,   55,   97,   98,   28,   29,
    0,    0,    0,    0,    0,    0,   55,   55,    0,    0,
    0,    0,    0,    0,    0,   38,   39,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,   56,
   56,   56,   56,    0,   56,   56,   56,   56,    0,  146,
    0,    0,    0,  124,    0,    0,    0,    0,   56,   56,
    0,    0,   52,   52,   52,   52,    0,   52,   52,  124,
    0,   53,   53,   53,   53,    0,   53,   53,    0,    0,
    0,   52,   52,  124,    0,    0,    0,    0,    0,    0,
   53,   53,  269,  270,    0,    0,    0,    0,    0,    0,
    0,  146,    0,    0,    0,  146,  146,  146,  146,  146,
  146,  146,  146,  146,    0,  146,  146,  146,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,    0,   50,   50,   50,   50,    0,    0,   50,    0,
    0,   51,   51,   51,   51,    0,    0,   51,    0,    0,
    0,   50,   50,  146,    0,    0,    0,    0,    0,    0,
   51,   51,   97,   98,   28,   29,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
    0,   38,   39,    0,    0,    0,    0,    0,    0,    0,
    0,    0,    0,    0,    0,    0,    0,    0,    0,  146,
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
  146,
};
}
static short yycheck[];
static { yycheck(); }
static void yycheck() {
yycheck = new short[] {                         33,
   40,   22,   55,   58,   59,   43,   40,   45,   40,   43,
   58,   45,   41,  215,   46,   58,   53,   47,   40,   54,
   55,   40,   49,   41,   41,   59,   77,  116,   55,   50,
   59,   41,   53,   54,   55,  256,   33,  213,  258,  227,
  258,   41,  287,   40,   44,   40,   43,  286,   45,   59,
  238,   46,   41,   37,  286,  287,   45,  259,   42,   59,
  262,   50,   59,   47,  266,  241,  242,   41,  289,  158,
   44,   41,   91,   33,   44,   93,   93,  263,  264,  281,
   40,  111,   47,   43,   41,   45,  123,   44,  125,  123,
   59,  126,  143,  144,  145,  277,  125,  279,  280,   59,
  125,  123,  123,  123,  125,  126,  290,  160,  257,  258,
   33,  258,  101,  296,  297,  104,  259,   40,  298,  299,
   43,   59,   45,  153,   40,  178,  123,  293,  294,  295,
  181,  158,  265,  266,  267,  268,   59,  136,  137,  138,
  139,  130,  131,  173,  174,   46,  183,  298,  299,   58,
   59,  178,   58,   59,   33,  257,  134,  135,  140,  141,
  213,   40,  183,  123,   43,  123,   45,  269,  270,  271,
  272,  273,  274,  156,  157,   33,  165,   40,   59,   59,
   59,  125,   40,  172,  237,   43,  213,   45,  269,  270,
  271,  272,  273,  274,  247,   59,  262,  261,  257,   59,
  123,   59,  257,  258,   59,   59,   41,   40,  123,  257,
  258,  200,  201,   41,  257,  258,   59,  206,  298,  124,
  260,  124,  256,  257,  258,  259,   41,   41,  260,  218,
  259,  257,   59,  278,   40,  269,  270,  271,  272,  273,
  274,  275,  276,  232,  123,   41,  125,  281,  282,  283,
  284,  285,  298,  291,  288,   59,   40,  299,  292,  256,
  257,  258,  259,  257,  298,  123,   41,  125,  257,  258,
  123,  299,  269,  270,  271,  272,  273,  274,  275,  276,
  125,  125,   33,   41,  281,  282,  283,  284,  285,   40,
   44,  288,   43,  259,   45,  292,  256,  257,  258,  259,
   44,  298,  269,  270,  271,  272,  273,  274,   59,  269,
  270,  271,  272,  273,  274,  275,  276,  260,   41,    0,
  125,  281,  282,  283,  284,  285,   59,  125,  288,    6,
   33,  125,  292,  256,  257,  258,  259,   40,  298,  125,
   43,    5,   45,  125,  125,  125,  269,  270,  271,  272,
  273,  274,  275,  276,  220,   96,   59,  129,  281,  282,
  283,  284,  285,  238,  133,  288,  237,   -1,   19,  292,
   -1,   -1,  123,   -1,  125,  298,   -1,  256,  257,  258,
  259,   33,  269,  270,  271,  272,  273,  274,   40,   -1,
   -1,   43,   -1,   45,   -1,   -1,  275,  276,  256,  257,
  258,  259,  281,  282,  283,  284,  285,   59,   -1,  288,
   -1,   -1,   -1,  292,   -1,   -1,   -1,  275,  276,  298,
  123,   -1,   -1,  281,  282,  283,  284,  285,   -1,   -1,
  288,   -1,   -1,   33,  292,   -1,   -1,   37,   -1,   -1,
  298,   41,   42,   43,   44,   45,   -1,   47,  269,  270,
  271,  272,  273,  274,   -1,   -1,   -1,   -1,   58,   59,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   33,
   -1,  123,   -1,   37,   -1,   -1,   -1,   41,   42,   43,
   44,   45,   -1,   47,   -1,   -1,   -1,   -1,   -1,   -1,
   33,   -1,   -1,   93,   -1,   59,   -1,   40,   41,   -1,
   43,   44,   45,   -1,   -1,  256,  257,  258,  259,   -1,
   -1,   -1,   -1,   37,   -1,   58,   59,   -1,   42,   43,
   -1,   45,   46,   47,  275,  276,   -1,   -1,   -1,   93,
  281,  282,  283,  284,  285,   59,   -1,  288,   -1,   -1,
   -1,  292,   -1,   -1,   -1,   -1,   -1,  298,   -1,   -1,
   93,   33,   -1,  256,  257,  258,  259,   -1,   40,   41,
   -1,   43,   44,   45,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,  275,  276,   -1,   -1,   58,   59,  281,  282,
  283,  284,  285,   -1,   -1,  288,   -1,   -1,   -1,  292,
   33,   -1,   -1,   -1,   -1,  298,   -1,   40,   41,   -1,
   43,   44,   45,   -1,  256,  257,  258,  259,   -1,   -1,
   -1,   93,   -1,   -1,   -1,   58,   59,   -1,   -1,   -1,
   -1,   -1,   -1,  275,  276,   -1,   -1,   33,   -1,  281,
  282,  283,  284,  285,   40,   41,  288,   -1,   44,   -1,
  292,   -1,   -1,   -1,   -1,   -1,  298,   -1,   -1,   -1,
   93,   -1,   58,   59,   -1,   -1,  256,  257,  258,  259,
   -1,  261,  262,  263,  264,  265,  266,  267,  268,   -1,
   -1,   -1,   -1,   -1,   37,  275,  276,   40,   -1,   42,
   43,   -1,   45,   46,   47,   -1,   -1,   93,   -1,   -1,
   -1,  291,  256,  257,  258,  259,   59,  261,  262,  263,
  264,  265,  266,  267,  268,   -1,   -1,   -1,   -1,   -1,
   -1,  275,  276,  256,  257,  258,  259,   -1,  261,  262,
  263,  264,  265,  266,  267,  268,   -1,  291,   -1,   -1,
   -1,   -1,  275,  276,   -1,   -1,  260,  261,  262,  263,
  264,  265,  266,  267,  268,   33,   -1,   -1,  291,   -1,
   -1,   -1,   40,   41,   33,   43,   44,   45,   -1,   -1,
  123,   40,   -1,   -1,   43,   -1,   45,  291,   -1,   -1,
   58,   59,   -1,   -1,  256,  257,  258,  259,   -1,  261,
  262,  263,  264,  265,  266,  267,  268,   -1,   -1,   -1,
   -1,   -1,   -1,  275,  276,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   93,   -1,   -1,   -1,  291,
   -1,   -1,   -1,  256,  257,  258,  259,   -1,  261,  262,
  263,  264,  265,  266,  267,  268,   -1,   -1,   33,   -1,
   -1,   -1,  275,  276,   -1,   40,   41,   33,   43,   44,
   45,   -1,   -1,   -1,   40,   -1,   -1,   43,  291,   45,
  256,  257,  258,  259,   59,  261,  262,  263,  264,  265,
  266,  267,  268,   59,   33,   -1,   -1,   -1,   -1,  275,
  276,   40,   41,   33,   43,   44,   45,   -1,   -1,   -1,
   40,   41,   -1,   43,   -1,   45,   -1,   -1,   93,   58,
   59,   -1,   -1,   -1,   -1,   -1,   -1,  260,  261,  262,
  263,  264,  265,  266,  267,  268,   33,   -1,   -1,   -1,
   -1,   -1,   -1,   40,   41,   -1,   43,   44,   45,   -1,
   -1,   -1,   -1,   -1,   93,   -1,   -1,   -1,  291,   33,
   -1,   58,   59,   -1,   -1,   -1,   40,   41,   33,   43,
   44,   45,   -1,   -1,   -1,   40,   41,   -1,   43,   44,
   45,   -1,   -1,   -1,   58,   59,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   58,   59,   -1,   93,   -1,  256,  257,
  258,  259,   -1,  261,  262,  263,  264,  256,  257,  258,
  259,   -1,   -1,   -1,   -1,   54,   -1,  275,  276,   93,
  269,  270,  271,  272,  273,  274,  275,  276,   93,   33,
   -1,   -1,   -1,   -1,   -1,   -1,   40,   41,   33,   43,
   44,   45,   -1,   -1,   -1,   40,   41,   -1,   43,   44,
   45,   -1,   -1,   -1,   58,   59,   -1,   -1,   -1,   33,
   -1,   -1,   -1,   58,   59,   -1,   40,   -1,   -1,   43,
   -1,   45,   -1,   -1,   -1,   -1,  115,   -1,   -1,   -1,
   -1,  256,  257,  258,  259,   -1,   -1,  126,   -1,   93,
  256,  257,  258,  259,   -1,   -1,   -1,   -1,   93,   -1,
  275,  276,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  275,
  276,   -1,   -1,   -1,   -1,   -1,   -1,  256,  257,  258,
  259,   -1,  261,  262,  263,  264,  256,  257,  258,  259,
   -1,   -1,   -1,   -1,   -1,   -1,  275,  276,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,  275,  276,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  256,
  257,  258,  259,   -1,  261,  262,  263,  264,   -1,   77,
   -1,   -1,   -1,  212,   -1,   -1,   -1,   -1,  275,  276,
   -1,   -1,  256,  257,  258,  259,   -1,  261,  262,  228,
   -1,  256,  257,  258,  259,   -1,  261,  262,   -1,   -1,
   -1,  275,  276,  242,   -1,   -1,   -1,   -1,   -1,   -1,
  275,  276,  251,  252,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,  129,   -1,   -1,   -1,  133,  134,  135,  136,  137,
  138,  139,  140,  141,   -1,  143,  144,  145,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,  256,  257,  258,  259,   -1,   -1,  262,   -1,
   -1,  256,  257,  258,  259,   -1,   -1,  262,   -1,   -1,
   -1,  275,  276,  181,   -1,   -1,   -1,   -1,   -1,   -1,
  275,  276,  256,  257,  258,  259,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,  275,  276,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  227,
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
  238,
};
}
final static short YYFINAL=3;
final static short YYMAXTOKEN=299;
final static String yyname[] = {
"end-of-file",null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,"'!'",null,null,null,"'%'",null,null,"'('","')'","'*'","'+'",
"','","'-'","'.'","'/'",null,null,null,null,null,null,null,null,null,null,"':'",
"';'",null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,"'['",null,"']'",null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,"'{'","'|'","'}'",null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
null,null,null,null,null,null,null,null,null,"IDENTIFIER","CONSTANT",
"STRING_LITERAL","EQ_ASS","AND_OP","OR_OP","EQ_OP","NE_OP","LE_OP","GE_OP",
"LESS_OP","GREAT_OP","INT","FLOAT","BOOL","CUE","PHRASE","TIME","INPUT",
"CURR_CUE","CURRENT_VALUE","DATA","MORE","VALUE_AT","CASE","RETURN","REPEAT",
"BREAK","CONTINUE","TIME_SIGNATURE","TEMPO","ADD","CONDUCTOR","MUSICIAN","IN",
"CHANGE","VOLUME","INSTRUMENT","PITCH","TO","BY","DB","RRPT",
};
final static String yyrule[] = {
"$accept : upbeat_src",
"upbeat_src : header conductor_block musician_blocks",
"header : header_time_sig header_tempo",
"header : header_tempo header_time_sig",
"header_time_sig : TIME_SIGNATURE CONSTANT '/' CONSTANT ';'",
"header_tempo : TEMPO CONSTANT ';'",
"$$1 :",
"conductor_block : CONDUCTOR '{' $$1 conductor_body '}'",
"conductor_block : error '}'",
"conductor_body : function_definition_list",
"conductor_body : statement_list function_definition_list",
"conductor_body : declaration_list function_definition_list",
"conductor_body : declaration_list statement_list function_definition_list",
"conductor_body : error '}'",
"conductor_body : error STRING_LITERAL",
"compound_statement : '{' '}'",
"compound_statement : '{' statement_list '}'",
"$$2 :",
"compound_statement : '{' $$2 declaration_list statement_list '}'",
"statement_list : statement",
"statement_list : statement_list statement",
"statement : compound_statement",
"statement : expression_statement",
"statement : adding_cue_statement",
"statement : musical_statement",
"statement : flow_control_statement",
"statement : error ';'",
"flow_control_statement : case_statement",
"flow_control_statement : repeat_statement",
"flow_control_statement : return_statement",
"flow_control_statement : continue_statement",
"flow_control_statement : break_statement",
"continue_statement : CONTINUE ';'",
"break_statement : BREAK ';'",
"return_statement : RETURN ';'",
"return_statement : RETURN expression ';'",
"expression_statement : expression ';'",
"expression_statement : ';'",
"$$3 :",
"case_statement : CASE $$3 '{' case_list '}'",
"$$4 :",
"case_statement : CASE $$4 case",
"case_list : case",
"case_list : case case_list",
"case : '(' expression ')' statement",
"$$5 :",
"repeat_statement : REPEAT '(' expression ')' $$5 statement",
"expression : logical_or_expression",
"expression : postfix_expression EQ_ASS expression",
"constant_expression : logical_or_expression",
"logical_or_expression : logical_and_expression",
"logical_or_expression : logical_or_expression OR_OP logical_and_expression",
"logical_and_expression : equality_expression",
"logical_and_expression : logical_and_expression AND_OP equality_expression",
"equality_expression : relational_expression",
"equality_expression : equality_expression EQ_OP relational_expression",
"equality_expression : equality_expression NE_OP relational_expression",
"relational_expression : range_expression",
"relational_expression : relational_expression LESS_OP range_expression",
"relational_expression : relational_expression GREAT_OP range_expression",
"relational_expression : relational_expression LE_OP range_expression",
"relational_expression : relational_expression GE_OP range_expression",
"range_expression : additive_expression",
"range_expression : additive_expression IN range_specifier",
"range_specifier : '(' expression ',' expression ')'",
"range_specifier : '[' expression ',' expression ')'",
"range_specifier : '(' expression ',' expression ']'",
"range_specifier : '[' expression ',' expression ']'",
"additive_expression : multiplication_expression",
"additive_expression : additive_expression '+' multiplication_expression",
"additive_expression : additive_expression '-' multiplication_expression",
"multiplication_expression : cast_expression",
"multiplication_expression : multiplication_expression '*' cast_expression",
"multiplication_expression : multiplication_expression '/' cast_expression",
"multiplication_expression : multiplication_expression '%' cast_expression",
"cast_expression : postfix_expression",
"cast_expression : unary_operator cast_expression",
"cast_expression : '(' type_specifier ')' cast_expression",
"postfix_expression : primary_expression",
"postfix_expression : input_expression",
"postfix_expression : postfix_expression '(' ')'",
"postfix_expression : postfix_expression '(' argument_expression_list ')'",
"postfix_expression : postfix_expression '.' DATA",
"input_expression : INPUT '.' VALUE_AT '(' expression ')'",
"input_expression : INPUT '.' CURRENT_VALUE",
"input_expression : INPUT '.' MORE",
"primary_expression : IDENTIFIER",
"primary_expression : CURR_CUE",
"primary_expression : CONSTANT",
"primary_expression : STRING_LITERAL",
"primary_expression : '(' expression ')'",
"primary_expression : error ')'",
"unary_operator : '+'",
"unary_operator : '-'",
"unary_operator : '!'",
"argument_expression_list : expression",
"argument_expression_list : argument_expression_list ',' expression",
"parameter_list : declaration",
"parameter_list : parameter_list ',' declaration",
"declaration_list : declaration ';'",
"declaration_list : declaration_list declaration ';'",
"declaration : type_specifier declarator",
"declarator : IDENTIFIER",
"declarator : IDENTIFIER EQ_ASS expression",
"type_specifier : INT",
"type_specifier : FLOAT",
"type_specifier : BOOL",
"type_specifier : CUE",
"type_specifier : PHRASE",
"type_specifier : TIME",
"function_definition_list : function_definition",
"function_definition_list : function_definition_list function_definition",
"$$6 :",
"function_definition : IDENTIFIER '(' ')' $$6 compound_statement",
"$$7 :",
"$$8 :",
"function_definition : IDENTIFIER '(' $$7 parameter_list ')' $$8 compound_statement",
"$$9 :",
"function_definition : type_specifier IDENTIFIER '(' ')' $$9 compound_statement",
"$$10 :",
"$$11 :",
"function_definition : type_specifier IDENTIFIER '(' $$10 parameter_list ')' $$11 compound_statement",
"adding_cue_statement : ADD expression expression ';'",
"musical_statement : phrase_expression ';'",
"musical_statement : phrase_control_expression ';'",
"phrase_control_expression : CHANGE change_parameter to_by_option expression",
"change_parameter : VOLUME",
"change_parameter : INSTRUMENT",
"change_parameter : PITCH",
"to_by_option : TO",
"to_by_option : BY",
"phrase_expression : first_phrase continuing_phrases",
"first_phrase : repeated_phrase",
"first_phrase : one_time_phrase",
"repeated_phrase : DB ':' musical_phrase RRPT",
"repeated_phrase : DB ':' musical_phrase RRPT constant_expression",
"one_time_phrase : DB musical_phrase DB",
"continuing_phrases : continued_repeated_phrase continuing_phrases",
"continuing_phrases : continued_one_time_phrase continuing_phrases",
"continuing_phrases :",
"musical_phrase : IDENTIFIER",
"musical_phrase : IDENTIFIER '|' musical_phrase",
"musical_phrase : CONSTANT",
"musical_phrase : CONSTANT '|' musical_phrase",
"continued_repeated_phrase : ':' musical_phrase RRPT",
"continued_repeated_phrase : ':' musical_phrase RRPT constant_expression",
"continued_one_time_phrase : musical_phrase DB",
"musician_blocks : musician_block",
"musician_blocks : musician_blocks musician_block",
"$$12 :",
"musician_block : MUSICIAN STRING_LITERAL '{' $$12 musician_body '}'",
"musician_body : statement_list cue_response_list",
"musician_body : declaration_list cue_response_list",
"musician_body : declaration_list statement_list cue_response_list",
"musician_body : declaration_list statement_list",
"cue_response_list : cue_response",
"cue_response_list : cue_response cue_response_list",
"$$13 :",
"cue_response : STRING_LITERAL $$13 compound_statement",
};

//#line 2139 "upbeat-a.yacc"
  // *******************************************
  // JAVA CODE THAT IS ADDED TO THE PARSER CLASS
  // *******************************************
  /* a reference to the lexer object */
  private Yylex lexer;
  private SymbolTable current_symbol_table;
  public static int yyerrors;
  public static int yywarnings;
  
  // This is used to determine which measure we start playing music at if a play statement
  // appears outside of processCue
  private int startMeasure = 1;
  // Total number of errors encountered
  
  private final Hashtable<String, short[][]> optable = new Hashtable<String, short[][]>();
  private final short castTable[][];
  
  // This is appended to the end of any temporary variable names we create
  // This ensures that all temporary variables have unique names.  Also, it
  // keeps track of how many there are (if we care)
  // DO NOT USE THIS DIRECTLY!  INSTEAD CALL TempIdentifier()!
  private int tempCounter;
  
  private int TempIdentifier() {
	  tempCounter++;
	  return tempCounter;
  }
  
  /* interface to the lexer */
  private int yylex () {
    int yyl_return = -1;
    try {
      yyl_return = lexer.yylex();
    }
    catch (IOException e) {
      System.err.println("IO error :"+e);
    }
    return yyl_return;
  }

  /* error reporting */
  public void yyerror (String error) {
    System.err.println ("Error: " + error + " at " + lexer.lexer_loc());
    yyerrors++;
  }
  
  /* warning reporting */
  public void yywarning (String warning) {
	  System.err.println("Warning: " + warning + " at " + lexer.lexer_loc());
	  yywarnings++;
  }

  /* lexer is created in the constructor */
  public parser(Reader r) {
    lexer = new Yylex(r, this);
    yyerrors = 0;
    yywarnings = 0;
    current_symbol_table = new SymbolTable();
    	// since we have no args, the parent is void, and it's a special top-level (global) symboltable.
    
    // This is used to check to see if a cast is legal
    // Note that casting a string to a string is illegal
    // This is because we don't have an actual keyword for string types
    /*
     * 0. Not allowed.  Give an error
     * 1. Allowed, but give a warning
     * 2. Allowed, perform cast and don't give any message
     * 3. Allowed, and no cast needed
     */
    castTable = new short[][]{
    	/* from/to	  ubVOID, ubINT, ubFLOAT, ubBOOL, ubCUE, ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{   3, 		0,		0,		0,		0,		0,		0,		0	},
        /*ubINT*/	{   0,		3,		2,		0,		0,		0,		2,		0	},
        /*ubFLOAT*/	{   0,		1,		3,		0,		0,		0,		1,		0	},
        /*ubBOOL*/	{   0,		0,		0,		3,		0,		0,		0,		0	},
        /*ubCUE*/	{   0,		0,		0,		0,		3,		0,		0,		0	},
        /*ubPHRASE*/{   0,		0,		0,		0,		0,		3,		0,		0	},
        /*ubTIME*/	{   0,		2,		1,		0,		0,		0,		3,		0	},
        /*ubSTRING*/{   0,		0,		0,		0,		0,		0,		0,		0	}
    };
  
    /*
     * 0. Not allowed
     * 1. Allowed; use both arguments as-is; result type is the same.
     * 2. Allowed; use both arguments as-is; result is java bool
     * 3. Special: assigning strings (rval) to CUE types (lval)
     * 4. Special: assigning strings (rval) to PHRASE types (lval)
     * 5. Special: cast right argument from java int to java String; result is left type
     * 6. Special: cast left argument from java int to java String; result is right type
     * 7. Allowed: cast right argument to left type; result is left type
     * 8. Allowed: cast left argument to right type; result is right type
     * 9. Allowed: cast right argument to left type; result is bool
     * 10. Allowed: cast left argument to right type; result is bool
     */
    optable.put(new String("="), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		1,		7,		0,		0,		0,		7,		0	},
    	/*ubFLOAT*/	{	0,		7,		1,		0,		0,		0,		7,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		1,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		1,		0,		0,		3	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		1,		0,		4	},
    	/*ubTIME*/	{	0,		7,		7,		0,		0,		0,		1,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String("+"), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		1,		8,		0,		0,		0,		8,		6	},
    	/*ubFLOAT*/	{	0,		7,		1,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		7,		0,		0,		0,		0,		1,		0	},
    	/*ubSTRING*/{	0,		5,		0,		0,		0,		0,		0,		1	}
      });
    optable.put(new String("-"), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		1,		8,		0,		0,		0,		8,		0	},
    	/*ubFLOAT*/	{	0,		7,		1,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		7,		0,		0,		0,		0,		1,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String("*"), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		1,		8,		0,		0,		0,		8,		0	},
    	/*ubFLOAT*/	{	0,		7,		1,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		7,		0,		0,		0,		0,		1,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String("/"), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		1,		8,		0,		0,		0,		8,		0	},
    	/*ubFLOAT*/	{	0,		7,		1,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		7,		0,		0,		0,		0,		1,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String("%"), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		1,		0,		0,		0,		0,		8,		0	},
    	/*ubFLOAT*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		7,		0,		0,		0,		0,		1,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String("<"), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		2,		10,		0,		0,		0,		9,		0	},
    	/*ubFLOAT*/	{	0,		9,		2,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		10,		0,		0,		0,		0,		2,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String(">"), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		2,		10,		0,		0,		0,		9,		0	},
    	/*ubFLOAT*/	{	0,		9,		2,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		10,		0,		0,		0,		0,		2,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String("<="), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		2,		10,		0,		0,		0,		9,		0	},
    	/*ubFLOAT*/	{	0,		9,		2,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		10,		0,		0,		0,		0,		2,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String(">="), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		2,		10,		0,		0,		0,		9,		0	},
    	/*ubFLOAT*/	{	0,		9,		2,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		10,		0,		0,		0,		0,		2,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String("=="), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		2,		0,		0,		0,		0,		9,		0	},
    	/*ubFLOAT*/	{	0,		0,		2,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		2,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		2,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		2,		0,		0	},
    	/*ubTIME*/	{	0,		10,		0,		0,		0,		0,		2,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String("!="), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		2,		0,		0,		0,		0,		9,		0	},
    	/*ubFLOAT*/	{	0,		0,		2,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		2,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		2,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		2,		0,		0	},
    	/*ubTIME*/	{	0,		10,		0,		0,		0,		0,		2,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String("&&"), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubFLOAT*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		1,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });
    optable.put(new String("||"), new short[][]{
    	/* left/right	ubVOID,	ubINT,	ubFLOAT,ubBOOL,	ubCUE,	ubPHRASE,ubTIME,ubSTRING */
    	/*ubVOID*/ 	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubINT*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubFLOAT*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubBOOL*/	{	0,		0,		0,		1,		0,		0,		0,		0	},
    	/*ubCUE*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubPHRASE*/{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubTIME*/	{	0,		0,		0,		0,		0,		0,		0,		0	},
    	/*ubSTRING*/{	0,		0,		0,		0,		0,		0,		0,		0	}
      });

    
    tempCounter = 0;
  }
  
  private String upbeatTypeName( upbeatVal.Type type ) {
	  switch( type ){
	  case ubVOID:
		  return "void";
	  case ubINT:
		  return "int";
	  case ubFLOAT:
		  return "float";
	  case ubBOOL:
		  return "bool";
	  case ubCUE:
		  return "cue";
	  case ubPHRASE:
		  return "phrase";
	  case ubTIME:
		  return "time";
	  case ubSTRING:
		  return "string";
	  }
	  return "Unrecognized type";
  }
  
  private String javaTypeName( upbeatVal.Type type ) {
	  switch( type ){
	  case ubVOID:
		  return "void";
	  case ubINT:
		  return "int";
	  case ubFLOAT:
		  return "double";
	  case ubBOOL:
		  return "boolean";
	  case ubCUE:
		  return "Cue";
	  case ubPHRASE:
		  return "MusicPhrase";
	  case ubTIME:
		  return "int";
	  case ubSTRING:
		  return "String";
	  }
	  return "Unrecognized type";
  }
  
  /*private boolean is_cast_allowed( upbeatVal.Type oldType, upbeatVal.Type newType ) {
	  return castTable[oldType.ordinal()][newType.ordinal()];
  }*/
  
  private String force_cast( upbeatVal.Type oldType, upbeatVal.Type newType ) {

	  if( oldType == null ) {
		  throw new Error("Attempting to cast from an unknown type");
	  }
	  if( newType == null ) {
		  throw new Error("Attempting to cast to an unknown type");
	  }

	  String cast = new String("");
	  short i = castTable[oldType.ordinal()][newType.ordinal()];
	  if( i == 0 ) {
	  // Disallow cast
		  yyerror("Illegal cast from " + upbeatTypeName(oldType) + " to " + upbeatTypeName(newType));
		  return cast;
	  }
	  else {
		  cast = cast.concat("(" + javaTypeName(newType) + ")");
	  }
	  
	  return cast;
  }
  
  private String perform_cast( upbeatVal.Type oldType, upbeatVal.Type newType ) {
	  if( oldType == null ) {
		  throw new Error("Attempting to cast from an unknown type");
	  }
	  if( newType == null ) {
		  throw new Error("Attempting to cast to an unknown type");
	  }
	  
	  String cast = new String("");
	  short i = castTable[oldType.ordinal()][newType.ordinal()];
	  switch( i ) {
	  // Disallow cast
	  case 0:
		  yyerror("Illegal cast from " + upbeatTypeName(oldType) + " to " + upbeatTypeName(newType));
		  return cast;
	  case 1:
		  yywarning("Casting from " + upbeatTypeName(oldType) + " to " + upbeatTypeName(newType));
	  case 2:
		  cast = cast.concat("(" + javaTypeName(newType) + ")");
		  return cast;
	  case 3:
		  return cast;
	  default:
		  throw new Error("Received illegal cast table value.");
	  }
  }
  
  // This is just a dummy function used for convenience...
  private upbeatVal CreateFunctionCall( upbeatVal funcName ) {
	  upbeatVal temp = new upbeatVal();
	  temp.listTypes = new LinkedList< upbeatVal.Type >();
	  temp.listExprs = new LinkedList< String >();
	  return CreateFunctionCall( funcName, temp );
  }
  
  private upbeatVal CreateFunctionCall( upbeatVal funcName, upbeatVal args ) {
	  
	  LinkedList< upbeatVal.Type > paramTypes = current_symbol_table.GetParamTypes( funcName.sval );
	  LinkedList< upbeatVal.Type > argTypes = args.listTypes;
	  LinkedList< String > argExprs = args.listExprs;
	  
	  Iterator< upbeatVal.Type > paramIter = paramTypes.iterator();
	  Iterator< upbeatVal.Type > argIter = argTypes.iterator();
	  Iterator< String > exprIter = argExprs.iterator();
	  
	  String newCode = funcName.code;
	  newCode = newCode.concat("(");
	  
	  while( paramIter.hasNext() && argIter.hasNext() && exprIter.hasNext() ) {
		  upbeatVal.Type argType = argIter.next();
		  upbeatVal.Type paramType = paramIter.next();
		  String expr = exprIter.next();
		  // If the argument and parameter have the same types, we don't need to cast
		  if( argType == paramType ) {
			  newCode = newCode.concat( expr );
		  }
		  else {
			  newCode = newCode.concat( perform_cast( argType, paramType ) );
			  newCode = newCode.concat(expr);
		  }
			  
		  // If we still have more to go, we need to add in the commas!
		  if( paramIter.hasNext() || argIter.hasNext() || exprIter.hasNext() )
			  newCode = newCode.concat(", ");
	  }
	  
	  if( paramIter.hasNext() || argIter.hasNext() || exprIter.hasNext() ) {
		  yyerror("Call to function " + funcName.code + " has incorrect number of arguments");
	  }
	  
	  newCode = newCode.concat(")");
	  
	  upbeatVal ret = new upbeatVal(newCode);
	  ret.type = current_symbol_table.GetFuncReturnType( funcName.sval );
	  
	  return ret;
  }
  
  private upbeatVal apply_op (String op, String lcode, String rcode, 
		  upbeatVal.Type ltype, upbeatVal.Type rtype) {
	  upbeatVal p = new upbeatVal();
	  if(op == null) {
		  throw new Error("attempt to apply unknown operator");
	  }
	  if(lcode == null || rcode == null) {
		  throw new Error("attempt to apply operator " + op + " with code missing");
	  }
	  if(ltype == null || rtype == null) {
		  throw new Error("attempt to apply operator " + op + " with code missing");
	  }
	  short i = optable.get(op)[ltype.ordinal()][rtype.ordinal()];
	  switch(i) {
	  case 0:
		  yyerror("Operation " + op + " not allowed on type " + upbeatTypeName(ltype) + " (left) and " +
				  upbeatTypeName(rtype) + " (right)");
		  break;
	  case 1:
		  p.code = lcode + " " + op + " " + rcode;
		  p.type = ltype;
		  break;
	  case 2:
		  p.code = lcode + " " + op + " " + rcode;
		  p.type = upbeatVal.Type.ubBOOL;
		  break;
	  case 3:
		  p.code = lcode + " = new " + javaTypeName(upbeatVal.Type.ubCUE) + "(" + rcode + ")";
		  p.type = upbeatVal.Type.ubCUE;
		  break;
	  case 4:
		  p.code = lcode + " = new " + javaTypeName(upbeatVal.Type.ubPHRASE) + "(" + rcode + ")";
		  p.type = upbeatVal.Type.ubPHRASE;
		  break;
	  case 5:
		  p.code = lcode + " " + op + " Integer.toString(" + rcode + ")";
		  p.type = ltype;
		  break;
	  case 6:
		  p.code = "Integer.toString(" + lcode + ") " + op + " " + rcode;
		  p.type = rtype;
		  break;
	  case 7:
		  p.code = lcode + " " + op + perform_cast(rtype, ltype) + rcode;
		  p.type = ltype;
		  break;
	  case 8:
		  p.code = perform_cast(ltype, rtype) + lcode + " " + op + rcode;
		  p.type = rtype;
		  break;
	  case 9:
		  p.code = lcode + " " + op + perform_cast(rtype, ltype) + rcode;
		  p.type = upbeatVal.Type.ubBOOL;
		  break;
	  case 10:
		  p.code = perform_cast(ltype, rtype) + lcode + " " + op + rcode;
		  p.type = upbeatVal.Type.ubBOOL;
		  break;
	  default:
		  yyerror("Undefined operation with given operator and types; this really shouldn't happen");
	  }
	  
	  // We're going to fully parenthesize our expressions.  However, we don't want to parenthesize our
	  // assignment expressions or else we'll get code like: int (foo = 2);
	  if( !op.equals("=") )
		  p.code = "(" + p.code + ")";
	  return p;
  }

  private static long getNextTempName = 0;
  private static String getNextTempName()
  {
	  return "t_up_" + (getNextTempName++);
  }
  
  private static int musicianChannelCounter = 0;
  private static int getNextMusicianChannel() {
	  int chan = musicianChannelCounter++;
	  if(chan == 9) {
		  chan = musicianChannelCounter++;
	  }
	  if(chan > 15) {
		  throw new Error("Upbeat currently supports only 15 musicians to comply with MIDI restrictions");
	  }
	  return chan;
  }
  
  private String generate_conductor_code(String declarations, String statements, String functions) {
  	String compiled_code = new String("");
	compiled_code = compiled_code.concat(
			"package upbeat.sample;\n\n" +
			"import upbeat.Conductor;\n" +
			"import upbeat.Manager;\n" +
			"import upbeat.types.Cue;\n\n" +
			"public class CompiledConductor extends Conductor {\n" +
			" 	// Conductor member variable declarations will go here\n" +
			declarations +
			"\n" +
			"	CompiledConductor() {\n" +
			"		super();\n\n" +
			"		// Conductor member variable initializations will go here\n" +
			statements +
			"\n" +
			"	}\n\n" +
			"	CompiledConductor( Manager man ) {\n" +
			"		super(man);\n" +
			"\n" +		
			"		// Conductor member variable initializations will go here\n" +
			statements +
			"	}\n\n" +
			functions +
			"}");

	return compiled_code;
  }
  
  /* here's how we use the lexer/parser */
  public static void main(String args[]) throws IOException {
	  int parse_retval = -1;
	  parser yyparser = new parser(new FileReader(args[0]));
	  yyparser.yydebug = false;
	  
	  String destDir = "upbeat/sample/";
	  File fdestDir = new File(destDir);
	  try {
		  if(!fdestDir.exists()) {
			  fdestDir.mkdirs();
		  }
	  } catch (Exception e) {
		  System.err.println("Error creating destination directory: " + destDir);
	  }

	  System.out.println("Compiling Upbeat file:  " + args[0]);

	  parse_retval = yyparser.yyparse();
	  if(parse_retval == 0 && yyerrors == 0) {
		  try {
			  /* Write code files */
			  /* Application */
			  FileWriter fstream = new FileWriter(destDir + "CompiledUpbeatApplication.java");
			  BufferedWriter out = new BufferedWriter(fstream);
			  System.out.println("Writing CompiledUpbeatApplication.java ...");
			  out.write(yyparser.yyval.code);
			  out.close();
			  /* Conductor */
			  fstream = new FileWriter(destDir + "CompiledConductor.java");
			  out = new BufferedWriter(fstream);
			  System.out.println("Writing CompiledConductor.java ...");
			  out.write(yyparser.yyval.sval);
			  out.close();

			  /* Musicians */
			  Enumeration<String> k;
			  Hashtable<String, String> musicians = (Hashtable)yyparser.yyval.obj;
			  k = musicians.keys();
			  while(k != null && k.hasMoreElements()) {
				  String key = k.nextElement();
				  fstream = new FileWriter(destDir + "Musician_" + key + ".java");
				  out = new BufferedWriter(fstream);
				  System.out.println("Writing Musician_" + key + ".java ...");
				  out.write(musicians.get(key));
				  out.close();
			  }
		  } catch (Exception e) {
			  System.err.println("Error in writing out code: " + e);
		  }
		  System.out.println("Successful parse with " + yyerrors + " errors and " + yywarnings + " warnings!\n Resulting code written to: " + fdestDir.getAbsolutePath() );
	  } else {
		  System.out.print("Parse error.  Returned " + parse_retval + " with " + yyerrors + " errors and " + yywarnings + " warnings.\n");
	  }
	  
	  System.exit(yyerrors);
  }
//#line 1638 "parser.java"
//###############################################################
// method: yylexdebug : check lexer state
//###############################################################
void yylexdebug(int state,int ch)
{
String s=null;
  if (ch < 0) ch=0;
  if (ch <= YYMAXTOKEN) //check index bounds
     s = yyname[ch];    //now get it
  if (s==null)
    s = "illegal-symbol";
  debug("state "+state+", reading "+ch+" ("+s+")");
}





//The following are now global, to aid in error reporting
int yyn;       //next next thing to do
int yym;       //
int yystate;   //current parsing state from state table
String yys;    //current token string


//###############################################################
// method: yyparse : parse input and execute indicated items
//###############################################################
int yyparse()
{
boolean doaction;
  init_stacks();
  yynerrs = 0;
  yyerrflag = 0;
  yychar = -1;          //impossible char forces a read
  yystate=0;            //initial state
  state_push(yystate);  //save it
  val_push(yylval);     //save empty value
  while (true) //until parsing is done, either correctly, or w/error
    {
    doaction=true;
    if (yydebug) debug("loop"); 
    //#### NEXT ACTION (from reduction table)
    for (yyn=yydefred[yystate];yyn==0;yyn=yydefred[yystate])
      {
      if (yydebug) debug("yyn:"+yyn+"  state:"+yystate+"  yychar:"+yychar);
      if (yychar < 0)      //we want a char?
        {
        yychar = yylex();  //get next token
        if (yydebug) debug(" next yychar:"+yychar);
        //#### ERROR CHECK ####
        if (yychar < 0)    //it it didn't work/error
          {
          yychar = 0;      //change it to default string (no -1!)
          if (yydebug)
            yylexdebug(yystate,yychar);
          }
        }//yychar<0
      yyn = yysindex[yystate];  //get amount to shift by (shift index)
      if ((yyn != 0) && (yyn += yychar) >= 0 &&
          yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
        {
        if (yydebug)
          debug("state "+yystate+", shifting to state "+yytable[yyn]);
        //#### NEXT STATE ####
        yystate = yytable[yyn];//we are in a new state
        state_push(yystate);   //save it
        val_push(yylval);      //push our lval as the input for next rule
        yychar = -1;           //since we have 'eaten' a token, say we need another
        if (yyerrflag > 0)     //have we recovered an error?
           --yyerrflag;        //give ourselves credit
        doaction=false;        //but don't process yet
        break;   //quit the yyn=0 loop
        }

    yyn = yyrindex[yystate];  //reduce
    if ((yyn !=0 ) && (yyn += yychar) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
      {   //we reduced!
      if (yydebug) debug("reduce");
      yyn = yytable[yyn];
      doaction=true; //get ready to execute
      break;         //drop down to actions
      }
    else //ERROR RECOVERY
      {
      if (yyerrflag==0)
        {
        yyerror("syntax error");
        yynerrs++;
        }
      if (yyerrflag < 3) //low error count?
        {
        yyerrflag = 3;
        while (true)   //do until break
          {
          if (stateptr<0)   //check for under & overflow here
            {
            yyerror("stack underflow. aborting...");  //note lower case 's'
            return 1;
            }
          yyn = yysindex[state_peek(0)];
          if ((yyn != 0) && (yyn += YYERRCODE) >= 0 &&
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
            {
            if (yydebug)
              debug("state "+state_peek(0)+", error recovery shifting to state "+yytable[yyn]+" ");
            yystate = yytable[yyn];
            state_push(yystate);
            val_push(yylval);
            doaction=false;
            break;
            }
          else
            {
            if (yydebug)
              debug("error recovery discarding state "+state_peek(0)+" ");
            if (stateptr<0)   //check for under & overflow here
              {
              yyerror("Stack underflow. aborting...");  //capital 'S'
              return 1;
              }
            state_pop();
            val_pop();
            }
          }
        }
      else            //discard this token
        {
        if (yychar == 0)
          return 1; //yyabort
        if (yydebug)
          {
          yys = null;
          if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
          if (yys == null) yys = "illegal-symbol";
          debug("state "+yystate+", error recovery discards token "+yychar+" ("+yys+")");
          }
        yychar = -1;  //read another
        }
      }//end error recovery
    }//yyn=0 loop
    if (!doaction)   //any reason not to proceed?
      continue;      //skip action
    yym = yylen[yyn];          //get count of terminals on rhs
    if (yydebug)
      debug("state "+yystate+", reducing "+yym+" by rule "+yyn+" ("+yyrule[yyn]+")");
    if (yym>0)                 //if count of rhs not 'nil'
      yyval = val_peek(yym-1); //get current semantic value
    yyval = dup_yyval(yyval); //duplicate yyval if ParserVal is used as semantic value
    switch(yyn)
      {
//########## USER-SUPPLIED ACTIONS ##########
case 1:
//#line 376 "upbeat-a.yacc"
{
			yyval = new upbeatVal("Generating compiled Upbeat code for " + val_peek(0).ival + " musicians.\n");
			
			String app_code = new String();
			
			app_code = app_code.concat("package upbeat.sample;\n\n" +
					"import upbeat.jmusiclib.*;\n" +
					"import upbeat.*;\n\n" +
					"public class CompiledUpbeatApplication implements UpbeatApplication {\n" +
					"	public static void main( String [] args ) {\n" +
"		// Right now, we're just going to assume that there is one input argument, and that it is a file name.\n" +
"		// When we implement real time, we will need to check to see if there is an additional flag to see\n" +
"		// whether we want real time or not.  The implementation of the Manager class we instantiate here will\n" +
"		// be dependent on whether or not we want to run in real time.  However, for now, just assume it's always\n" +
"		// offline.\n" +
"\n" +		
"		// Create the Manager, Conductor, and Musician(s).\n" +
"		Manager manager;\n" +
"		//if( realtime )\n" +
"		// manager = new RealTimeManager();\n" +
"		//else\n" +
"		manager = new OfflineManager();\n" +
"\n" +		
"		TempoOptions tempoOptions = new CompiledTempoOptions();\n" +
"		Conductor conductor = new CompiledConductor(manager);\n");
			
			Hashtable<String, String> musicians;
			Enumeration<String> k;
			/* TODO: clean up the way we assign musician code*/
			musicians = (Hashtable)val_peek(0).obj;
			k = musicians.keys();
			  while(k != null && k.hasMoreElements()) {
				  String key = k.nextElement();
				  app_code = app_code.concat("\t\tMusician " + key + " = new Musician_" + key + "();\n");
			  }
			
			app_code = app_code.concat(
"		// Set the manager up with the input file, the Conductor, and the Musician(s)\n" +
"		if( args.length < 1 ) {\n" +
"			System.out.println(\"Warning: No input source supplied!\");\n" +
"		}\n" +
"		else {\n" +
"			String inputname = args[0];\n" +
"			if( !manager.SetInputSource(inputname) ) {\n" +
"				System.out.printf(\"Error: Could not open source:%s\", inputname);\n" +
"			}\n" +
"		}\n" +
"\n" +			
"		manager.SetJMusicWrapper(new JMusicWrapper());\n" +
"		manager.SetTempoOptions(tempoOptions);\n" +
"		manager.SetConductor(conductor);\n" +
"\n" +				
"		// We're going to need to have an individual AddMusician call for each Musician\n");
			
			k = musicians.keys();
			  while(k != null && k.hasMoreElements()) {
				  String key = k.nextElement();
				  app_code = app_code.concat("\t\tmanager.AddMusician(" + key + ");\n");
			  }

			  app_code = app_code.concat(
"		// Note, if we're writing the output to a MIDI file on disk we might want to have a way of\n" +
"		// providing an output file name.\n" +

"		try {\n" +
"		manager.MakeSomeMusic();\n" +
"		} catch (Exception e) {\n" +
"		};\n" +
"	}\n" +
"}\n\n");

			app_code = app_code.concat(val_peek(2).code);
			
			String conductor_code = new String(val_peek(1).code);

			/*System.out.println(">>>>>>>>>>>>> CompiledUpbeatApplication.java >>>>>>>>>>>>>>>>>\n\n" + app_code +*/
			/*		"\n>>>>>>>>>>>>> CompiledConductor.java >>>>>>>>>>>>>>>>>\n\n" + conductor_code);*/
			k = musicians.keys();
			while(k != null && k.hasMoreElements()) {
				String key = k.nextElement();
			/*	System.out.println(">>>>>>>>>>>>> Musician_" + key + ".java >>>>>>>>>>>>>>>>>\n\n" + musicians.get(key) + "\n\n");*/
			}
			/* 1. Construct CompiledUpbeatApplication:
			 * 	a. iterate through musicians by NAME and construct Musician NAME = new Musician_NAME()
			 * 	b. also iterate through and do manager.addMusician(NAME);
			 *  c. stick the tempo options on the end!
			 * 2. Construct CompiledConductor
			 *  a. stick in 
			 */
			if(current_symbol_table.numSymbols() > 0) {
				System.err.println("Warning: global symbol table has symbols; this is unusual in Upbeat:\n" + current_symbol_table.toString());
			}
			yyval = new upbeatVal(app_code);
			yyval.sval = conductor_code;
			yyval.obj = new Hashtable<String, String>();
			k = musicians.keys();
			while(k != null && k.hasMoreElements()) {
				String key = k.nextElement();
				((Hashtable<String,String>)yyval.obj).put(key, musicians.get(key));
			}
    	}
break;
case 2:
//#line 481 "upbeat-a.yacc"
{ yyval = new upbeatVal("class CompiledTempoOptions extends TempoOptions {\n" +
    	"\tCompiledTempoOptions(){\n\t\t// This is where and how we set the header information\n" +
    	val_peek(1).code + val_peek(0).code +
    	"\t}\n}\n"); }
break;
case 3:
//#line 486 "upbeat-a.yacc"
{ yyval = new upbeatVal("class CompiledTempoOptions extends TempoOptions {\n" +
	    "\tCompiledTempoOptions(){\n\t\t// This is where and how we set the header information\n" +
	    val_peek(0).code + val_peek(1).code +
	    "\t}\n}\n"); }
break;
case 4:
//#line 494 "upbeat-a.yacc"
{ yyval = new upbeatVal("\t\tsuper.TIME_SIGNATURE_TOP = " + val_peek(3).ival +
    						 ";\n\t\tsuper.TIME_SIGNATURE_BOTTOM = " + val_peek(1).ival + ";\n"); }
break;
case 5:
//#line 500 "upbeat-a.yacc"
{
    	if (val_peek(1).ival < 1 || val_peek(1).ival > 1000) {
    	/*TODO: what are the legal tempo values?*/
    	/*TODO: define a warning and an error function for parsing? lexing?*/
    		System.err.print("Warning: TEMPO must be an integer between 1 and 1000, representing beats per minute.  " +
    		"Defaulting to 100 bpm.\n");
    		val_peek(1).ival = 100;
    	}
    	yyval = new upbeatVal("\t\tsuper.TEMPO = " + val_peek(1).ival + ";\n"); }
break;
case 6:
//#line 513 "upbeat-a.yacc"
{
    		SymbolTable t = new SymbolTable(current_symbol_table);
    		current_symbol_table = t;
    		current_symbol_table.inConductor = true;
    	}
break;
case 7:
//#line 519 "upbeat-a.yacc"
{
    	yyval = new upbeatVal(val_peek(1).code);
    	current_symbol_table = current_symbol_table.parent;
    		/* 
    		 * Write out CompiledConductor class with:
    		 * 1. Declarations for all local variables in Upbeat Conductor {} block
    		 * 2. Constructors for CompiledConductor class that initialize all local Upbeat variables
    		 * 3. All functions defined in Conductor {} block
    		 * 4. 
    		 */
    	}
break;
case 8:
//#line 531 "upbeat-a.yacc"
{
    	System.err.println("Error in Conductor.");
    	if( current_symbol_table != null )
    		current_symbol_table = current_symbol_table.parent;
    }
break;
case 9:
//#line 540 "upbeat-a.yacc"
{
    	String declarations = new String("");
    	/* there are no declarations*/
    	String statements = new String("");
    	/* there are no statements*/
    	String functions = new String("");
    	functions = functions.concat(val_peek(0).code);
    	
    	String compiled_code = generate_conductor_code(declarations, statements, functions);

    	yyval = new upbeatVal(compiled_code);
    	/* TODO: Check to make sure there's at least 1 Conduct() method
    	 * 
    	 */
    }
break;
case 10:
//#line 556 "upbeat-a.yacc"
{
    	String declarations = new String("");
    	/* there are no declarations*/
    	String statements = new String(val_peek(1).code);
    	String functions = new String("");
    	functions = functions.concat(val_peek(0).code);
    	
    	String compiled_code = generate_conductor_code(declarations, statements, functions);

    	yyval = new upbeatVal(compiled_code);
    	/* TODO: Check to make sure there's at least 1 Conduct() method
    	 * 
    	 */
    }
break;
case 11:
//#line 571 "upbeat-a.yacc"
{
    	String declarations = new String(val_peek(1).code);
    	String statements = new String("");
    	/* there are no statements*/
    	String functions = new String(val_peek(0).code);
    	
    	String compiled_code = generate_conductor_code(declarations, statements, functions);

    	yyval = new upbeatVal(compiled_code);
    	/* TODO: Check to make sure there's at least 1 Conduct() method
    	 * 
    	 */
    }
break;
case 12:
//#line 585 "upbeat-a.yacc"
{
    	String declarations = new String(val_peek(2).code);
    	String statements = new String(val_peek(1).code);
    	String functions = new String(val_peek(0).code);
    	
    	String compiled_code = generate_conductor_code(declarations, statements, functions);

    	yyval = new upbeatVal(compiled_code);
    	/* TODO: Check to make sure there's at least 1 Conduct() method
    	 * 
    	 */
    }
break;
case 13:
//#line 598 "upbeat-a.yacc"
{
    	System.err.println("Error in Conductor body.");
    }
break;
case 14:
//#line 602 "upbeat-a.yacc"
{
    	System.err.println("Error in Conductor body.  Missing closing } perhaps?");
    }
break;
case 15:
//#line 609 "upbeat-a.yacc"
{
    		yyval = new upbeatVal("{ }");
    	}
break;
case 16:
//#line 613 "upbeat-a.yacc"
{
    		/* No Symbol table needed, since there are no declarations.*/
    		yyval = new upbeatVal("{\n" + val_peek(1).code + " }\n");
    	}
break;
case 17:
//#line 618 "upbeat-a.yacc"
{ /* start new symbol table:*/
    		/*  1. create new symbol table new_table*/
    		/*  2. assign current_sym_table to be its parent*/
    		/*  3. assign new_table to current_sym_table*/
  			SymbolTable t = new SymbolTable(current_symbol_table);
  			current_symbol_table = t;
		}
break;
case 18:
//#line 626 "upbeat-a.yacc"
{
    		yyval = new upbeatVal("{\n" + val_peek(2).code + "\n" + val_peek(1).code + " }\n");
    	  	current_symbol_table = current_symbol_table.parent;
    	}
break;
case 19:
//#line 634 "upbeat-a.yacc"
{
    	yyval = new upbeatVal(val_peek(0).code);
    }
break;
case 20:
//#line 638 "upbeat-a.yacc"
{
    	yyval = new upbeatVal(val_peek(1).code + val_peek(0).code);
    }
break;
case 21:
//#line 645 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).code);
    	}
break;
case 22:
//#line 649 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).code);
		}
break;
case 23:
//#line 653 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).code);
		}
break;
case 24:
//#line 657 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).code);
		}
break;
case 25:
//#line 661 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).code);
		}
break;
case 26:
//#line 665 "upbeat-a.yacc"
{
    	System.err.println("Error in statement.");
    }
break;
case 32:
//#line 680 "upbeat-a.yacc"
{
	    	if( !current_symbol_table.inRepeat )
	    		yyerror("Continue statement outside of a Repeat statement");
	    	
	    	yyval = new upbeatVal("continue;\n");
		}
break;
case 33:
//#line 690 "upbeat-a.yacc"
{
	    	if( !current_symbol_table.inRepeat )
	    		yyerror("Break statement outside of a Repeat statement");
	    	
	    	yyval = new upbeatVal("break;\n");
		}
break;
case 34:
//#line 700 "upbeat-a.yacc"
{
    		if( !current_symbol_table.inConductorFunc )
    			yyerror("Return statement outside of a function definition");
    		else {
    			if( current_symbol_table.GetCurrentReturnType() != upbeatVal.Type.ubVOID )
	    			yyerror("Function " + current_symbol_table.myName + " requires a return value" );
	    		
    			current_symbol_table.Returns();
    		}
    		yyval = new upbeatVal("return;\n");
    	}
break;
case 35:
//#line 712 "upbeat-a.yacc"
{
    		if( !current_symbol_table.inConductorFunc ) {
    			yyerror("Return statement outside of a function definition");
    			/* this is a dummy for now*/
    			yyval = new upbeatVal("return;\n");
    		}
    		else {
	    		yyval = new upbeatVal("return " + perform_cast( val_peek(1).type, current_symbol_table.GetCurrentReturnType() ) + val_peek(1).code + ";\n");
	    		current_symbol_table.Returns();
    		}
    	}
break;
case 36:
//#line 727 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(1).code + ";\n");
    	}
break;
case 37:
//#line 731 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(";\n");
    	}
break;
case 38:
//#line 738 "upbeat-a.yacc"
{
    		if( !current_symbol_table.inConductorFunc 
       		 && !current_symbol_table.inCueResponse )
       			yyerror("Case statement outside a function definition or cue response");
	    }
break;
case 39:
//#line 744 "upbeat-a.yacc"
{
	    	yyval = new upbeatVal( val_peek(1).code );
	    }
break;
case 40:
//#line 748 "upbeat-a.yacc"
{
	    	if( !current_symbol_table.inConductorFunc 
	       	&& !current_symbol_table.inCueResponse )
	       		yyerror("Case statement outside a function definition or cue response");
	    }
break;
case 41:
//#line 754 "upbeat-a.yacc"
{
	    	yyval = new upbeatVal( val_peek(0).code );
	    }
break;
case 42:
//#line 761 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).code);
    	}
break;
case 43:
//#line 765 "upbeat-a.yacc"
{
	    	String newCode = new String("");
	    	newCode = newCode.concat( val_peek(1).code );
	    	newCode = newCode.concat( "else " );
	    	newCode = newCode.concat( val_peek(0).code );
	    	
	    	yyval = new upbeatVal( newCode );
	    }
break;
case 44:
//#line 777 "upbeat-a.yacc"
{
	    	String newCode = new String("if(");
	    	newCode = newCode.concat(val_peek(2).code);
	    	newCode = newCode.concat(") {\n");
	    	newCode = newCode.concat( val_peek(0).code );
	    	newCode = newCode.concat( "}\n" );
	    	
	    	yyval = new upbeatVal( newCode );
	    }
break;
case 45:
//#line 790 "upbeat-a.yacc"
{
    	if( !current_symbol_table.inConductorFunc 
          	&& !current_symbol_table.inCueResponse )
          	yyerror("Repeat statement outside a function definition or cue response");
		if (val_peek(1).type == upbeatVal.Type.ubBOOL) {
			String newCode = new String ("while (");
			newCode = newCode.concat (val_peek(1).code);
			newCode = newCode.concat (") {\n");
			yyval = new upbeatVal( newCode );
    	}
		else {
			String ub_REPEATlimit = new String( getNextTempName() ); /* need to get the name to use later*/
			String newCode = new String("int " + ub_REPEATlimit + " = " + perform_cast(val_peek(1).type, upbeatVal.Type.ubINT) + val_peek(1).code  + ";\n");
			/* now generate for loop*/
    		newCode = newCode.concat ("for (int ub_REPEATscroll = 1; ub_REPEATscroll <= " + ub_REPEATlimit + "; ub_REPEATscroll++ ) {\n");
    		yyval = new upbeatVal( newCode );
		}
		
		SymbolTable t = new SymbolTable(current_symbol_table);
		t.inRepeat = true;
		current_symbol_table = t;
	}
break;
case 46:
//#line 813 "upbeat-a.yacc"
{
    	yyval = new upbeatVal( val_peek(1).code + val_peek(0).code + " }\n" );
    	
    	/* We need to reset the symbol table*/
    	current_symbol_table = current_symbol_table.parent;
    }
break;
case 47:
//#line 824 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(0).code );
			yyval.type = val_peek(0).type;
		}
break;
case 48:
//#line 829 "upbeat-a.yacc"
{
    		if( !val_peek(2).assignable ) {
    			yyerror("Cannot assign to expression to left of =");
    			if( val_peek(2).code != null && val_peek(2).code.charAt(0) == '(' && val_peek(2).code.charAt(val_peek(2).code.length() - 1) == ')' )
    				yyerror("If it is parenthesized, try removing the parentheses");
    		}

    		/* If we haven't checked to make sure we've defined the stuff used in the*/
    		/* post fix expression, we need to do the check now!*/
    		if( !val_peek(2).definitionCheck ) {
    			if( current_symbol_table.GetDefLine( val_peek(2).sval ) == -1 ) {
    				yyerror("Identifier: " + val_peek(2).sval + " is undefined");
    				if(val_peek(2).sval.toLowerCase().equals("return")) {
    					yyerror("Perhaps you meant \"Return\" with a capital \"R\"?");
    				} else if (val_peek(2).sval.toLowerCase().equals("input")) {
    					yyerror("Perhaps you meant \"input\", all lowercase?");
    				} /* else no help*/
    			}
    		}

			yyval = apply_op("=", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
			/* TODO: (optional) mark in symbol table that it's been assigned */
      	}
break;
case 49:
//#line 856 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(0).code );
			yyval.type = val_peek(0).type;
		}
break;
case 50:
//#line 864 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(0).code );
			yyval.type = val_peek(0).type;
		}
break;
case 51:
//#line 869 "upbeat-a.yacc"
{
			yyval = apply_op("||", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	  	}
break;
case 52:
//#line 876 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(0).code );
			yyval.type = val_peek(0).type;
		}
break;
case 53:
//#line 881 "upbeat-a.yacc"
{
			yyval = apply_op("&&", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	  	}
break;
case 54:
//#line 888 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(0).code );
			yyval.type = val_peek(0).type;
		}
break;
case 55:
//#line 893 "upbeat-a.yacc"
{
			yyval = apply_op("==", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	  	}
break;
case 56:
//#line 897 "upbeat-a.yacc"
{
			yyval = apply_op("!=", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	  	}
break;
case 57:
//#line 904 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(0).code );
			yyval.type = val_peek(0).type;
		}
break;
case 58:
//#line 909 "upbeat-a.yacc"
{
			yyval = apply_op("<", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	  	}
break;
case 59:
//#line 913 "upbeat-a.yacc"
{
			yyval = apply_op(">", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	  	}
break;
case 60:
//#line 917 "upbeat-a.yacc"
{
			yyval = apply_op("<=", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	  	}
break;
case 61:
//#line 921 "upbeat-a.yacc"
{
			yyval = apply_op(">=", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	  	}
break;
case 62:
//#line 928 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(0).code );
			yyval.type = val_peek(0).type;
		}
break;
case 63:
//#line 933 "upbeat-a.yacc"
{
    		if( val_peek(2).type != upbeatVal.Type.ubINT && val_peek(2).type != upbeatVal.Type.ubFLOAT ) {
    			yyerror("Expression to left of 'in' keyword on line does not evaluate to an " +
    					upbeatTypeName(upbeatVal.Type.ubINT) + " or a " + upbeatTypeName(upbeatVal.Type.ubFLOAT) + ".");
    		}
    		
	    	upbeatVal.Type tempType;
	    	if( val_peek(2).type == upbeatVal.Type.ubINT && 
	    	    val_peek(0).rangeLeftType == upbeatVal.Type.ubINT &&
	    	    val_peek(0).rangeRightType == upbeatVal.Type.ubINT )
	    		tempType = upbeatVal.Type.ubINT;
	    	else
	    		tempType = upbeatVal.Type.ubFLOAT;
	    	
	    	/* Lets get our additive expression code right*/
	    	/* We need to make sure to cast it if need be...*/
	    	String addExpr = new String("(");
	    	if( val_peek(2).type != tempType )
	    		addExpr = addExpr.concat( "(" + javaTypeName(tempType) + ")" );
	    	addExpr = addExpr.concat(val_peek(2).code);
	    	addExpr = addExpr.concat(")");
	    	
	    	/* Do the same for our right and left expressions in our*/
	    	/* range specifier*/
	    	String leftExpr = new String("(");
	    	if( val_peek(0).rangeLeftType != tempType )
	    		leftExpr = leftExpr.concat( "(" + javaTypeName(tempType) + ")" );
	    	leftExpr = leftExpr.concat(val_peek(0).rangeLeft);
	    	leftExpr = leftExpr.concat(")");
	    	
	    	String rightExpr = new String("(");
	    	if( val_peek(0).rangeRightType != tempType )
	    		rightExpr = rightExpr.concat( "(" + javaTypeName(tempType) + ")" );
	    	rightExpr = rightExpr.concat(val_peek(0).rangeRight);
	    	rightExpr = rightExpr.concat(")");
	    	
	    	/* Finally, we need to make sure our operations are correct*/
	    	/* depending on whether the range is open or closed.*/
	    	String leftOp;
	    	if( val_peek(0).leftOpen )
	    		leftOp = new String(" > ");
	    	else
	    		leftOp = new String(" >= ");
	    	
	    	String rightOp;
	    	if( val_peek(0).rightOpen )
	    		rightOp = new String(" < ");
	    	else
	    		rightOp = new String(" <= ");
	    	
	    	String newCode = new String("((");
	    	newCode = newCode.concat( addExpr + leftOp + leftExpr );
	    	newCode = newCode.concat( ") && (");
	    	newCode = newCode.concat( addExpr + rightOp + rightExpr );
	    	newCode = newCode.concat("))");
	    	
	    	yyval = new upbeatVal(newCode);
	    	yyval.type = upbeatVal.Type.ubBOOL;
	    }
break;
case 64:
//#line 996 "upbeat-a.yacc"
{
	    	if( val_peek(3).type != upbeatVal.Type.ubINT && 
	    		val_peek(3).type != upbeatVal.Type.ubFLOAT ) {
	    		yyerror("Left half of range specifier does not evaluate to an " 
	    				+ upbeatTypeName(upbeatVal.Type.ubINT) + " or a " + upbeatTypeName(upbeatVal.Type.ubFLOAT));
	    	}
	    	if( val_peek(1).type != upbeatVal.Type.ubINT && 
	    		val_peek(1).type != upbeatVal.Type.ubFLOAT ) {
	    		yyerror("Right half of range specifier does not evaluate to an " 
	    				+ upbeatTypeName(upbeatVal.Type.ubINT) + " or a " + upbeatTypeName(upbeatVal.Type.ubFLOAT));
	    	}
	    	
	    	yyval = new upbeatVal();
	    	yyval.rangeLeft = new String( val_peek(3).code );
	    	yyval.rangeRight = new String( val_peek(1).code );
	    	yyval.leftOpen = true;
	    	yyval.rightOpen = true;
	    	yyval.rangeLeftType = val_peek(3).type;
	    	yyval.rangeRightType = val_peek(1).type;
	    }
break;
case 65:
//#line 1017 "upbeat-a.yacc"
{
	    	if( val_peek(3).type != upbeatVal.Type.ubINT && 
	    		val_peek(3).type != upbeatVal.Type.ubFLOAT ) {
	    		yyerror("Left half of range specifier does not evaluate to an " 
	    				+ upbeatTypeName(upbeatVal.Type.ubINT) + " or a " + upbeatTypeName(upbeatVal.Type.ubFLOAT));
	    	}
	    	if( val_peek(1).type != upbeatVal.Type.ubINT && 
	    		val_peek(1).type != upbeatVal.Type.ubFLOAT ) {
	    		yyerror("Right half of range specifier does not evaluate to an " 
	    				+ upbeatTypeName(upbeatVal.Type.ubINT) + " or a " + upbeatTypeName(upbeatVal.Type.ubFLOAT));
	    	}
	    	
	    	yyval = new upbeatVal();
	    	yyval.rangeLeft = new String( val_peek(3).code );
	    	yyval.rangeRight = new String( val_peek(1).code );
	    	yyval.leftOpen = false;
	    	yyval.rightOpen = true;
	    	yyval.rangeLeftType = val_peek(3).type;
	    	yyval.rangeRightType = val_peek(1).type;
	    }
break;
case 66:
//#line 1038 "upbeat-a.yacc"
{
	    	if( val_peek(3).type != upbeatVal.Type.ubINT && 
	    		val_peek(3).type != upbeatVal.Type.ubFLOAT ) {
	    		yyerror("Left half of range specifier does not evaluate to an " 
	    				+ upbeatTypeName(upbeatVal.Type.ubINT) + " or a " + upbeatTypeName(upbeatVal.Type.ubFLOAT));
	    	}
	    	if( val_peek(1).type != upbeatVal.Type.ubINT && 
	    		val_peek(1).type != upbeatVal.Type.ubFLOAT ) {
	    		yyerror("Right half of range specifier does not evaluate to an " 
	    				+ upbeatTypeName(upbeatVal.Type.ubINT) + " or a " + upbeatTypeName(upbeatVal.Type.ubFLOAT));
	    	}
	    	
	    	yyval = new upbeatVal();
	    	yyval.rangeLeft = new String( val_peek(3).code );
	    	yyval.rangeRight = new String( val_peek(1).code );
	    	yyval.leftOpen = true;
	    	yyval.rightOpen = false;
	    	yyval.rangeLeftType = val_peek(3).type;
	    	yyval.rangeRightType = val_peek(1).type;
	    }
break;
case 67:
//#line 1059 "upbeat-a.yacc"
{
	    	if( val_peek(3).type != upbeatVal.Type.ubINT && 
	    		val_peek(3).type != upbeatVal.Type.ubFLOAT ) {
	    		yyerror("Left half of range specifier does not evaluate to an " 
	    				+ upbeatTypeName(upbeatVal.Type.ubINT) + " or a " + upbeatTypeName(upbeatVal.Type.ubFLOAT));
	    	}
	    	if( val_peek(1).type != upbeatVal.Type.ubINT && 
	    		val_peek(1).type != upbeatVal.Type.ubFLOAT ) {
	    		yyerror("Right half of range specifier does not evaluate to an " 
	    				+ upbeatTypeName(upbeatVal.Type.ubINT) + " or a " + upbeatTypeName(upbeatVal.Type.ubFLOAT));
	    	}
	    	
	    	yyval = new upbeatVal();
	    	yyval.rangeLeft = new String( val_peek(3).code );
	    	yyval.rangeRight = new String( val_peek(1).code );
	    	yyval.leftOpen = false;
	    	yyval.rightOpen = false;
	    	yyval.rangeLeftType = val_peek(3).type;
	    	yyval.rangeRightType = val_peek(1).type;
	    }
break;
case 68:
//#line 1083 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(0).code );
			yyval.type = val_peek(0).type;
		}
break;
case 69:
//#line 1088 "upbeat-a.yacc"
{
    		yyval = apply_op("+", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
    	}
break;
case 70:
//#line 1092 "upbeat-a.yacc"
{
	    	yyval = apply_op("-", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	    }
break;
case 71:
//#line 1099 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(0).code );
			yyval.type = val_peek(0).type;
		}
break;
case 72:
//#line 1104 "upbeat-a.yacc"
{
	    	yyval = apply_op("*", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	    }
break;
case 73:
//#line 1108 "upbeat-a.yacc"
{
    		yyval = apply_op("/", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	    }
break;
case 74:
//#line 1112 "upbeat-a.yacc"
{
			yyval = apply_op("%", val_peek(2).code, val_peek(0).code, val_peek(2).type, val_peek(0).type);
	    }
break;
case 75:
//#line 1119 "upbeat-a.yacc"
{
    		yyval = new upbeatVal( val_peek(0).code );
    		yyval.type = val_peek(0).type;
    		
    		/* If we haven't checked to make sure we've defined the stuff used in the*/
    		/* post fix expression, we need to do the check now!*/
    		if( !val_peek(0).definitionCheck ) {
    			if( current_symbol_table.GetDefLine( val_peek(0).sval ) == -1 ) {
    				yyerror("Identifier: " + val_peek(0).sval + " is undefined");
    				if(val_peek(0).sval.toLowerCase().equals("return")) {
    					yyerror("Perhaps you meant \"Return\" with a capital \"R\"?");
    				} else if (val_peek(0).sval.toLowerCase().equals("input")) {
    					yyerror("Perhaps you meant \"input\", all lowercase?");
    				} /* else no help*/
    			}
    		}
    			
    	}
break;
case 76:
//#line 1138 "upbeat-a.yacc"
{
	    	yyval = new upbeatVal( val_peek(1).code + val_peek(0).code );
	    	yyval.type = val_peek(0).type;
	    	
	    	switch( val_peek(1).unaryOp ) {
	    	case uopPLUS:
	    		switch( val_peek(0).type ) {
	    		case ubVOID:
	    		case ubBOOL:
	    		case ubCUE:
	    		case ubPHRASE:
	    		case ubSTRING:
	    			yyerror("Attempting to apply unary operator '+' to an expression of type: "
	    					+ upbeatTypeName(val_peek(0).type));
	    		}
	    		break;
	    	case uopMINUS:
	    		switch( val_peek(0).type ) {
	    		case ubVOID:
	    		case ubBOOL:
	    		case ubCUE:
	    		case ubPHRASE:
	    		case ubSTRING:
	    			yyerror("Attempting to apply unary operator '-' to an expression of type: "
	    					+ upbeatTypeName(val_peek(0).type));
	    		}
	    		break;
	    	case uopNOT:
	    		switch( val_peek(0).type ) {
	    		case ubVOID:
	    		case ubINT:
	    		case ubFLOAT:
	    		case ubCUE:
	    		case ubPHRASE:
	    		case ubTIME:
	    		case ubSTRING:
	    			yyerror("Attempting to apply unary operator '!' to an expression of type: "
	    					+ upbeatTypeName(val_peek(0).type));
	    		}
	    		break;
	    	}
	    }
break;
case 77:
//#line 1181 "upbeat-a.yacc"
{
    		String newCode = new String( force_cast(val_peek(0).type, val_peek(2).type) );
    		newCode = newCode.concat( val_peek(0).code );
	    	yyval = new upbeatVal(newCode);
	    	yyval.type = val_peek(2).type;
	    }
break;
case 78:
//#line 1197 "upbeat-a.yacc"
{
    		yyval = new upbeatVal( val_peek(0).code );
    		yyval.type = val_peek(0).type;
    		yyval.sval = val_peek(0).sval;
    		yyval.alreadyPostFixed = false;
    		
    		/* Up the line we might need to do a definition check*/
    		yyval.definitionCheck = val_peek(0).definitionCheck;
    		yyval.assignable = val_peek(0).assignable;
    	}
break;
case 79:
//#line 1208 "upbeat-a.yacc"
{
	    	yyval = new upbeatVal( val_peek(0).code );
	    	yyval.type = val_peek(0).type;
	    	
	    	/* Don't think we need this here*/
	    	/*$$.sval = $1.sval;*/
	    	
	    	/* We never want to add a postfix operator after an input expression*/
	    	yyval.alreadyPostFixed = true;
	    	yyval.definitionCheck = true;
	    	yyval.assignable = false;
	    }
break;
case 80:
//#line 1221 "upbeat-a.yacc"
{
	    	if( val_peek(2).alreadyPostFixed )
				yyerror("Chaining of postfix expressions not allowed");
		    
		    /* Now let's do the type checking!*/
			if( current_symbol_table.GetFuncDefLine( val_peek(2).sval ) == -1 ) {
				yyerror("Function: " + val_peek(2).sval + " is undefined");
				yyval = val_peek(2);
			}
			else
				yyval = CreateFunctionCall( val_peek(2) );
			
			
			yyval.alreadyPostFixed = true;
			yyval.definitionCheck = true;
			yyval.assignable = false;
	    }
break;
case 81:
//#line 1239 "upbeat-a.yacc"
{
	    	if( val_peek(3).alreadyPostFixed )
				yyerror("Chaining of postfix expressions not allowed");

	    	/* Now let's do the type checking!*/
			if( current_symbol_table.GetFuncDefLine( val_peek(3).sval ) == -1 ) {
				yyerror("Function: " + val_peek(3).sval + " is undefined");
				yyval = val_peek(3);
			}
			else
				yyval = CreateFunctionCall( val_peek(3), val_peek(1) );
			
			yyval.alreadyPostFixed = true;
	    	yyval.definitionCheck = true;
	    	yyval.assignable = false;
	    }
break;
case 82:
//#line 1256 "upbeat-a.yacc"
{
    		if( val_peek(2).type != upbeatVal.Type.ubCUE ) {
    			yyerror("Expression must be of type " + upbeatTypeName(upbeatVal.Type.ubCUE) + " to have a data member");
    		}
	    	yyval = new upbeatVal( val_peek(2).code + ".data" );
	    	yyval.type = upbeatVal.Type.ubINT;
	    	yyval.alreadyPostFixed = true;
	    	/* Now let's do the type checking!*/
	    	if( !val_peek(2).definitionCheck ) {
				if( current_symbol_table.GetDefLine( val_peek(2).sval ) == -1 ) {
					yyerror("Using " + val_peek(2).sval + " without having declared it");
				}
	    	}
			yyval.sval = val_peek(2).sval;
	    	yyval.definitionCheck = true;
	    	yyval.assignable = true;
	    }
break;
case 83:
//#line 1277 "upbeat-a.yacc"
{
    		if( !current_symbol_table.inConductorFunc ) {
    			yyerror( "Attempting to use reserved word input while not in a Conductor function" );
    		}
			String newCode = new String("");
			newCode = newCode.concat(val_peek(5).code);
			newCode = newCode.concat(".");
			newCode = newCode.concat("ValueAt(");
			newCode = newCode.concat( perform_cast(val_peek(1).type, upbeatVal.Type.ubINT) );
			newCode = newCode.concat( val_peek(1).code );
			newCode = newCode.concat(")");
			
			if( val_peek(1).type != upbeatVal.Type.ubINT && val_peek(1).type != upbeatVal.Type.ubTIME ) {
				yyerror(" Expression:\n" + val_peek(1).code + "\nmust be either of type " + upbeatTypeName(upbeatVal.Type.ubINT) + " or "
						+ upbeatTypeName(upbeatVal.Type.ubTIME));
			}
			
			yyval = new upbeatVal( newCode );
			yyval.type = upbeatVal.Type.ubFLOAT;
		}
break;
case 84:
//#line 1298 "upbeat-a.yacc"
{
    		if( !current_symbol_table.inConductorFunc ) {
				yyerror( "Attempting to use reserved word input while not in a Conductor function" );
			}
	    	String newCode = new String("");
			newCode = newCode.concat(val_peek(2).code);
			newCode = newCode.concat(".");
			newCode = newCode.concat("CurrentValue()");
			yyval = new upbeatVal( newCode );
			yyval.type = upbeatVal.Type.ubFLOAT;
		}
break;
case 85:
//#line 1310 "upbeat-a.yacc"
{
    		if( !current_symbol_table.inConductorFunc ) {
				yyerror( "Attempting to use reserved word input while not in a Conductor function" );
			}
	    	String newCode = new String("");
			newCode = newCode.concat(val_peek(2).code);
			newCode = newCode.concat(".");
			newCode = newCode.concat("GetMore()");
			yyval = new upbeatVal( newCode );
			yyval.type = upbeatVal.Type.ubBOOL;
		}
break;
case 86:
//#line 1325 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).code);
    		yyval.sval = val_peek(0).sval;
    		yyval.type = current_symbol_table.GetType(val_peek(0).sval);
    		yyval.definitionCheck = false;
    		yyval.assignable = true;
    	}
break;
case 87:
//#line 1333 "upbeat-a.yacc"
{
    		if( !current_symbol_table.inCueResponse ) {
    			yyerror("Attempting to use " + val_peek(0).code + " while not in a cue response");
    		}
    		yyval = new upbeatVal(val_peek(0).code);
    		yyval.sval = val_peek(0).sval;
    		yyval.type = upbeatVal.Type.ubCUE;
    		yyval.definitionCheck = true;
    		yyval.assignable = false;
	    }
break;
case 88:
//#line 1344 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).code);
    		yyval.type = val_peek(0).type;
    		yyval.sval = val_peek(0).code;
    		yyval.definitionCheck = true;
    		yyval.assignable = false;
    	}
break;
case 89:
//#line 1352 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).sval);
    		yyval.sval = val_peek(0).code;
    		/* Agreed, that's a little confusing.*/
    		yyval.type = val_peek(0).type;
    		yyval.definitionCheck = true;
    		yyval.assignable = false;
    	}
break;
case 90:
//#line 1361 "upbeat-a.yacc"
{
    		yyval = new upbeatVal("(" + val_peek(1).code + ")");
    		yyval.type = val_peek(1).type;
    		yyval.sval = val_peek(2).code;
    		yyval.definitionCheck = true;
    		yyval.assignable = false;
    	}
break;
case 91:
//#line 1369 "upbeat-a.yacc"
{
	    	yyerror("Error in expression");
	    }
break;
case 92:
//#line 1376 "upbeat-a.yacc"
{
    		yyval = new upbeatVal("+");
    		yyval.unaryOp = upbeatVal.UnaryOp.uopPLUS;
    	}
break;
case 93:
//#line 1381 "upbeat-a.yacc"
{
			yyval = new upbeatVal("-");
			yyval.unaryOp = upbeatVal.UnaryOp.uopMINUS;
		}
break;
case 94:
//#line 1386 "upbeat-a.yacc"
{
			yyval = new upbeatVal("!");
			yyval.unaryOp = upbeatVal.UnaryOp.uopNOT;
		}
break;
case 95:
//#line 1394 "upbeat-a.yacc"
{
    		yyval = val_peek(0);
    		yyval.listTypes = new LinkedList<upbeatVal.Type>();
    		yyval.listTypes.add(val_peek(0).type);
    		yyval.listExprs = new LinkedList<String>();
    		yyval.listExprs.add(val_peek(0).code);
    	}
break;
case 96:
//#line 1402 "upbeat-a.yacc"
{
			/* We're not actually going to use this code...*/
			yyval = new upbeatVal( val_peek(2).code + ", " + val_peek(0).code );
			
			/* We need to build up a list of expression codes and types*/
			/* so we can do type checking and casting at the postfix_expression*/
			/* level of the grammar*/
			yyval.listTypes = val_peek(2).listTypes;
			yyval.listTypes.add(val_peek(0).type);
			yyval.listExprs = val_peek(2).listExprs;
			yyval.listExprs.add(val_peek(0).code);
		}
break;
case 97:
//#line 1418 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(0).code );
			yyval.listTypes = new LinkedList< upbeatVal.Type >();
			yyval.listTypes.add( val_peek(0).type );
		}
break;
case 98:
//#line 1424 "upbeat-a.yacc"
{
			yyval = new upbeatVal( val_peek(2).code + ", " + val_peek(0).code );
			yyval.listTypes = val_peek(2).listTypes;
			yyval.listTypes.add( val_peek(0).type );
		}
break;
case 99:
//#line 1434 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(1).code + ";");
    	}
break;
case 100:
//#line 1438 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(2).code + "\n" + val_peek(1).code + ";");
    	}
break;
case 101:
//#line 1445 "upbeat-a.yacc"
{
    		/* If we've got a phrase, we need to make sure we're not declaring it in the Conductor*/
    		if( val_peek(1).type == upbeatVal.Type.ubPHRASE && current_symbol_table.inConductor )
    			yyerror("Cannot declare phrases in Conductor block");
    		if( val_peek(1).type == upbeatVal.Type.ubCUE && current_symbol_table.inMusician )
    			yyerror("Cannot declare cues in Musician block");
    		
    		/* First, check if variable is declared already; if not, add to symbol table */
    		if(current_symbol_table.GetType(val_peek(0).sval) == null) {
    			current_symbol_table.AddSymbol(val_peek(0).sval, val_peek(1).type, lexer.current_line());
    		} else {
    			yyerror("Variable " + val_peek(0).sval + " already defined on line " +
    					current_symbol_table.GetDefLine(val_peek(0).sval) + " as an " +
    					current_symbol_table.GetType(val_peek(0).sval));
    		}
    		
    		/* Assignment type checking and code generation */
    		if(val_peek(0).obj instanceof String) {
    			/* Need to do assignment*/
    			yyval = apply_op("=", val_peek(0).code, (String)val_peek(0).obj, val_peek(1).type, val_peek(0).type);
    		} else {
    			yyval = new upbeatVal(val_peek(0).code);
    		}
    		yyval.code = val_peek(1).code + " " + yyval.code;
    		yyval.type = val_peek(1).type;
    	}
break;
case 102:
//#line 1475 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).code);
    		yyval.sval = val_peek(0).sval;
    	}
break;
case 103:
//#line 1480 "upbeat-a.yacc"
{
    		/* NOTE THAT ASSIGNMENT TYPE CHECKING OCCURS UP AT DECLARATION. */
    		/* TODO: (optional) mark in symbol table that it's been assigned */
    		yyval = new upbeatVal(val_peek(0).type);
    		yyval.sval = val_peek(2).sval;
    		yyval.code = val_peek(2).code;
    		yyval.obj = new String(val_peek(0).code);
    	}
break;
case 104:
//#line 1492 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(upbeatVal.Type.ubINT);
    		yyval.code = javaTypeName(upbeatVal.Type.ubINT);
    	}
break;
case 105:
//#line 1497 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(upbeatVal.Type.ubFLOAT);
    		yyval.code = javaTypeName(upbeatVal.Type.ubFLOAT);
    	}
break;
case 106:
//#line 1502 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(upbeatVal.Type.ubBOOL);
    		yyval.code = javaTypeName(upbeatVal.Type.ubBOOL);
    	}
break;
case 107:
//#line 1507 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(upbeatVal.Type.ubCUE);
    		yyval.code = javaTypeName(upbeatVal.Type.ubCUE);
    	}
break;
case 108:
//#line 1512 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(upbeatVal.Type.ubPHRASE);
    		yyval.code = javaTypeName(upbeatVal.Type.ubPHRASE);
    	}
break;
case 109:
//#line 1517 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(upbeatVal.Type.ubTIME);
    		yyval.code = javaTypeName(upbeatVal.Type.ubTIME);
    	}
break;
case 110:
//#line 1525 "upbeat-a.yacc"
{
    	yyval = new upbeatVal(val_peek(0).code);
	}
break;
case 111:
//#line 1529 "upbeat-a.yacc"
{
		yyval = new upbeatVal(val_peek(1).code + val_peek(0).code);
	}
break;
case 112:
//#line 1536 "upbeat-a.yacc"
{	
			/* First, check if variable is declared already; if not, add to symbol table*/
    		if(current_symbol_table.GetFuncReturnType(val_peek(2).code) == null) {
    			FunctionType fType = new FunctionType();
    			fType.SetReturnType( upbeatVal.Type.ubVOID );
    			current_symbol_table.AddFuncSymbol( val_peek(2).sval, fType, lexer.current_line());
    		} else {
    			yyerror("Function " + val_peek(2).sval + " already defined on line " +
    					current_symbol_table.GetFuncDefLine(val_peek(2).code));
    		}
    		
    		SymbolTable t = new SymbolTable(current_symbol_table);
			current_symbol_table = t;
			current_symbol_table.inConductorFunc = true;
			current_symbol_table.myName = val_peek(2).sval;
		}
break;
case 113:
//#line 1553 "upbeat-a.yacc"
{
			String funcode = new String("\n");
    		yyval = new upbeatVal(upbeatVal.Type.ubVOID);
    		if(val_peek(4).sval.equals("Conduct")) {
    			funcode = funcode.concat("protected ");
    		}
    		funcode = funcode.concat("void " + val_peek(4).code + "() throws Exception " + val_peek(0).code);
    		yyval.code = funcode;
    		current_symbol_table = current_symbol_table.parent;
		}
break;
case 114:
//#line 1564 "upbeat-a.yacc"
{	
    		/* We need a new symbol table to scope arguments to the function.*/
			SymbolTable t = new SymbolTable(current_symbol_table);
			current_symbol_table = t;
			current_symbol_table.inConductorFunc = true;
			current_symbol_table.myName = val_peek(1).sval;
			
			/* What follows is kind of weird.*/
			
			/* Basically, we need to create a new symbol table that corresponds with the code*/
			/* immediately inside this function call.  We want the parameters in the parameter_list*/
			/* below to be scoped only to the function.  However, we need to know what types the parameters*/
			/* are in order to create a symbol table entry for the function itself.  Furthermore, we need*/
			/* to have the function scoped one level above, which is why we call the current_symbol_table.parent.*/
			/* Finally, though, we want the function to be callable from in itself, so we need to add it*/
			/* to the symbol table before we process the compound_statement.  Otherwise, we wouldn't*/
			/* be able to do recursion.*/
    	}
break;
case 115:
//#line 1583 "upbeat-a.yacc"
{
	    	/* First, check if variable is declared already; if not, add to symbol table*/
			if(current_symbol_table.parent.GetFuncReturnType(val_peek(4).code) == null) {
				FunctionType fType = new FunctionType();
				fType.SetReturnType( upbeatVal.Type.ubVOID );
				fType.SetArgs( val_peek(1).listTypes );
				current_symbol_table.parent.AddFuncSymbol( val_peek(4).sval, fType, lexer.current_line());
			} else {
				yyerror("Function " + val_peek(4).sval + " already defined on line " +
						current_symbol_table.parent.GetFuncDefLine(val_peek(4).sval));
			}
	    }
break;
case 116:
//#line 1596 "upbeat-a.yacc"
{
    		String funcode = new String("\n");
    		yyval = new upbeatVal(upbeatVal.Type.ubVOID);
    		if(val_peek(6).sval.equals("Conduct")) {
    			funcode = funcode.concat("protected ");
    		}
    		funcode = funcode.concat("void " + val_peek(6).code + "(" + val_peek(3).code + ") throws Exception " + val_peek(0).code);
    		yyval.code = funcode;
        	current_symbol_table = current_symbol_table.parent;
    	}
break;
case 117:
//#line 1607 "upbeat-a.yacc"
{
	    	/* First, check if variable is declared already; if not, add to symbol table*/
			if(current_symbol_table.GetFuncReturnType(val_peek(2).code) == null) {
				FunctionType fType = new FunctionType();
				fType.SetReturnType( val_peek(3).type );
				current_symbol_table.AddFuncSymbol( val_peek(2).sval, fType, lexer.current_line());
			} else {
				yyerror("Function " + val_peek(2).sval + " already defined on line " +
						current_symbol_table.parent.GetFuncDefLine(val_peek(2).sval));
			}
			
			/* We need a new symbol table to scope arguments to the function.*/
			SymbolTable t = new SymbolTable(current_symbol_table);
			current_symbol_table = t;
			current_symbol_table.inConductorFunc = true;
			current_symbol_table.myName = val_peek(2).sval;
	    }
break;
case 118:
//#line 1625 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(5).type);
    		if(val_peek(4).sval.equals("Conduct")) {
    			yyerror("Conduct function should not have a return type");
    		}
    		yyval.code = "\n" + val_peek(5).code + " " + val_peek(4).code + "() throws Exception " + val_peek(0).code;
    		if( !current_symbol_table.returns ) {
    			yyerror("Function " + val_peek(4).sval + " does not return a value");
    		}
    		current_symbol_table = current_symbol_table.parent;
    	}
break;
case 119:
//#line 1637 "upbeat-a.yacc"
{
			/* We need a new symbol table to scope arguments to the function.*/
			SymbolTable t = new SymbolTable(current_symbol_table);
			current_symbol_table = t;
			current_symbol_table.inConductorFunc = true;
			current_symbol_table.myName = val_peek(1).sval;
    	}
break;
case 120:
//#line 1645 "upbeat-a.yacc"
{
	    	/* First, check if variable is declared already; if not, add to symbol table */
			if(current_symbol_table.parent.GetFuncReturnType(val_peek(4).code) == null) {
				FunctionType fType = new FunctionType();
				fType.SetReturnType( val_peek(5).type );
				fType.SetArgs( val_peek(1).listTypes );
				current_symbol_table.parent.AddFuncSymbol( val_peek(4).sval, fType, lexer.current_line());
			} else {
				yyerror("Function " + val_peek(4).sval + " already defined on line " +
						current_symbol_table.parent.GetFuncDefLine(val_peek(4).sval));
			}
	    }
break;
case 121:
//#line 1658 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(7).type);
    		if(val_peek(6).sval.equals("Conduct")) {
    			yyerror("Conduct function should not have a return type");
    		}
    		yyval.code = "\n" + val_peek(7).code + " " + val_peek(6).code + "(" + val_peek(3).code + ") throws Exception " + val_peek(0).code;
    		if( !current_symbol_table.returns ) {
    			yyerror("Function " + val_peek(6).sval + " does not return a value");
    		}
    		current_symbol_table = current_symbol_table.parent;
    	}
break;
case 122:
//#line 1674 "upbeat-a.yacc"
{
    	/* If we're trying to add a cue to the score from a Musician, it's an error!*/
    	if( !current_symbol_table.inConductorFunc )
    		yyerror("Attempting to Add a cue outside the definition of a function in the Conductor");
    	
    	String newCode = new String("");
    	newCode = newCode.concat( "AddCueToScore( " );
    	newCode = newCode.concat( perform_cast( val_peek(2).type, upbeatVal.Type.ubCUE ) );
    	newCode = newCode.concat( val_peek(2).code + ", " );
    	newCode = newCode.concat( perform_cast( val_peek(1).type, upbeatVal.Type.ubTIME) );
    	newCode = newCode.concat(val_peek(1).code + ");\n");
    	
    	yyval = new upbeatVal(newCode);
    }
break;
case 123:
//#line 1691 "upbeat-a.yacc"
{ yyval = new upbeatVal( val_peek(1).code + ";\n" ); }
break;
case 124:
//#line 1692 "upbeat-a.yacc"
{ yyval = new upbeatVal( val_peek(1).code + ";\n" ); }
break;
case 125:
//#line 1697 "upbeat-a.yacc"
{
    		if( !current_symbol_table.inMusician )
    			yyerror("Must be in a Musician to Change Volume, Pitch, or Instrument");
    		
    		String newCode = new String("getMusicMaker().change");
    		switch (val_peek(2).changeParam ){
    		case Pitch:
    			newCode = newCode.concat("Pitch");
    			break;
    		case Volume:
    			newCode = newCode.concat("Volume");
    			break;
    		case Instrument:
    			newCode = newCode.concat("Instrument");
    			break;
    		}
    		
    		switch (val_peek(1).toOrBy ){
    		case To:
    			newCode = newCode.concat("To");
    			break;
    		case By:
    			newCode = newCode.concat("By");
    			break;
    		}
    		
    		newCode = newCode.concat("(");
    		newCode = newCode.concat( perform_cast( val_peek(0).type, upbeatVal.Type.ubINT) );
    		newCode = newCode.concat(val_peek(0).code);
    		newCode = newCode.concat(", ");
    		if(current_symbol_table.inCueResponse) {
    			newCode = newCode.concat("cue.getTime()");
    		} else {
    			newCode = newCode.concat(String.format("%d", startMeasure));
    		}
    		newCode = newCode.concat(")");
    		yyval = new upbeatVal(newCode);
    	}
break;
case 126:
//#line 1738 "upbeat-a.yacc"
{ yyval = new upbeatVal( upbeatVal.ChangeParam.Volume ); }
break;
case 127:
//#line 1739 "upbeat-a.yacc"
{ yyval = new upbeatVal( upbeatVal.ChangeParam.Instrument ); }
break;
case 128:
//#line 1740 "upbeat-a.yacc"
{ yyval = new upbeatVal( upbeatVal.ChangeParam.Pitch ); }
break;
case 129:
//#line 1744 "upbeat-a.yacc"
{ yyval = new upbeatVal( upbeatVal.ToBy.To ); }
break;
case 130:
//#line 1745 "upbeat-a.yacc"
{ yyval = new upbeatVal( upbeatVal.ToBy.By ); }
break;
case 131:
//#line 1750 "upbeat-a.yacc"
{
    	if( !current_symbol_table.inMusician )
    		yyerror("Attempting to play things outside a Musician");
    	
    	String code = new String();
		String tempVarName = getNextTempName();
    	code = code.concat(String.format("MusicPhrase %s = new MusicPhrase();\n", tempVarName));
    	code = code.concat(val_peek(1).code);
    	code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, val_peek(1).sval));
    	
    	if (val_peek(0) != null) {
    		code = code.concat(val_peek(0).code);
    		code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, val_peek(0).sval));    		
    	}
    	
    	if( current_symbol_table.inCueResponse )
    		code = code.concat(String.format("getMusicMaker().appendPhraseAt(%s, cue.getTime())", tempVarName));
    	else
    		code = code.concat(String.format("getMusicMaker().appendPhraseAt(%s, %d)", tempVarName, startMeasure));
    	yyval = new upbeatVal(code);
    }
break;
case 134:
//#line 1780 "upbeat-a.yacc"
{
    		String code = new String();
    		String tempVarName = getNextTempName();
        	code = code.concat(String.format("MusicPhrase %s = new MusicPhrase();\n", tempVarName));
        	for (String p : val_peek(1).listval) {
        		code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, p));
        	}
    		code = code.concat(String.format("%s.setRepeat(-1);\n", tempVarName));
    		upbeatVal res = new upbeatVal(code);
    		res.sval = tempVarName;
    		yyval = res;
    	}
break;
case 135:
//#line 1793 "upbeat-a.yacc"
{
	    	String code = new String();
			String tempVarName = getNextTempName();
	    	code = code.concat(String.format("MusicPhrase %s = new MusicPhrase();\n", tempVarName));
	    	for (String p : val_peek(2).listval) {
	    		code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, p));
	    	}
			code = code.concat(String.format("%s.setRepeat(%s);\n", tempVarName, val_peek(0).code));
			upbeatVal res = new upbeatVal(code);
			res.sval = tempVarName;
			yyval = res;
    	}
break;
case 136:
//#line 1809 "upbeat-a.yacc"
{
    	String code = new String();
		String tempVarName = getNextTempName();
    	code = code.concat(String.format("MusicPhrase %s = new MusicPhrase();\n", tempVarName));
    	for (String p : val_peek(1).listval) {
    		code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, p));
    	}
		upbeatVal res = new upbeatVal(code);
		res.sval = tempVarName;
		yyval = res;
    }
break;
case 137:
//#line 1824 "upbeat-a.yacc"
{
    	String code = new String();
		String tempVarName = getNextTempName();
    	code = code.concat(String.format("MusicPhrase %s = new MusicPhrase();\n", tempVarName));
    	code = code.concat(val_peek(1).code);
    	code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, val_peek(1).sval));
    	
    	if (val_peek(0) != null) {
    		code = code.concat(val_peek(0).code);
    		code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, val_peek(0).sval));    		
    	}
    	
    	yyval = new upbeatVal(code);
    	yyval.sval = tempVarName;
    }
break;
case 138:
//#line 1840 "upbeat-a.yacc"
{
    	String code = new String();
		String tempVarName = getNextTempName();
    	code = code.concat(String.format("MusicPhrase %s = new MusicPhrase();\n", tempVarName));
    	code = code.concat(val_peek(1).code);
    	code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, val_peek(1).sval));
    	
    	if (val_peek(0) != null) {
    		code = code.concat(val_peek(0).code);
    		code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, val_peek(0).sval));    		
    	}
    	
    	yyval = new upbeatVal(code);
    	yyval.sval = tempVarName;
    }
break;
case 139:
//#line 1856 "upbeat-a.yacc"
{
    		yyval = null;
    	}
break;
case 140:
//#line 1863 "upbeat-a.yacc"
{
    		if(current_symbol_table.GetType(val_peek(0).sval) == null) {
    			yyerror("Using " + val_peek(0).sval + " without having declared it");
    		}
    		yyval = new upbeatVal("");
    		yyval.sval = val_peek(0).sval;
    		yyval.type = current_symbol_table.GetType(val_peek(0).sval);
    		if (yyval.type != upbeatVal.Type.ubPHRASE) {
    			yyerror ("Using a non-phrase variable in the musical phrase play statement is not allowed");
    		}
    		yyval.listval = new LinkedList<String>();
    		yyval.listval.add(val_peek(0).code);
		}
break;
case 141:
//#line 1877 "upbeat-a.yacc"
{
			if(current_symbol_table.GetType(val_peek(2).sval) == null) {
				yyerror("Using " + val_peek(2).sval + " without having declared it");
			}
			if( current_symbol_table.GetType(val_peek(2).sval) != upbeatVal.Type.ubPHRASE ) {
				yyerror("Using a non-phrase variable in a musical phrase play statement is not allowed");
			}
			yyval = new upbeatVal("");
			yyval.sval = val_peek(2).sval;
    		yyval.type = upbeatVal.Type.ubPHRASE;
			yyval.listval = new LinkedList<String>();
			yyval.listval.add(val_peek(2).code);
			if(val_peek(0).listval != null) {
				for(String p : val_peek(0).listval) {
					yyval.listval.add(p);
				}
			}
    	}
break;
case 142:
//#line 1896 "upbeat-a.yacc"
{
    	/*NOTE: ALL constants of type "ubPHRASE" are RESTS.*/
    	if(val_peek(0).type != upbeatVal.Type.ubPHRASE) {
    		yyerror ("Musical phrases can only contain variables of type " + upbeatTypeName(upbeatVal.Type.ubPHRASE) + " or RESTs");
    	}
    	yyval = new upbeatVal("");
    	yyval.listval = new LinkedList<String>();
    	yyval.listval.add("MusicPhrase.getREST()");
    }
break;
case 143:
//#line 1906 "upbeat-a.yacc"
{
    	/*NOTE: ALL constants of type "ubPHRASE" are RESTS.*/
    	if(val_peek(2).type != upbeatVal.Type.ubPHRASE) {
    		yyerror ("Musical phrases can only contain variables of type " + upbeatTypeName(upbeatVal.Type.ubPHRASE) + " or RESTs");
    	}
    	yyval = new upbeatVal("");
    	yyval.listval = new LinkedList<String>();
    	yyval.listval.add("MusicPhrase.getREST()");
    	
    	if(val_peek(0).listval != null) {
			for(String p : val_peek(0).listval) {
				yyval.listval.add(p);
			}
		}
    }
break;
case 144:
//#line 1925 "upbeat-a.yacc"
{
    	String code = new String();
		String tempVarName = getNextTempName();
    	code = code.concat(String.format("MusicPhrase %s = new MusicPhrase();\n", tempVarName));
    	for (String p : val_peek(1).listval) {
    		code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, p));
    	}
		code = code.concat(String.format("%s.setRepeat(-1);\n", tempVarName));
		upbeatVal res = new upbeatVal(code);
		res.sval = tempVarName;
		yyval = res;
    }
break;
case 145:
//#line 1938 "upbeat-a.yacc"
{
    	String code = new String();
		String tempVarName = getNextTempName();
    	code = code.concat(String.format("MusicPhrase %s = new MusicPhrase();\n", tempVarName));
    	
    	for (String p : val_peek(2).listval) {
    		code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, p));
    	}
		code = code.concat(String.format("%s.setRepeat(%s);\n", tempVarName, val_peek(0).code));
		upbeatVal res = new upbeatVal(code);
		res.sval = tempVarName;
		yyval = res;
    }
break;
case 146:
//#line 1955 "upbeat-a.yacc"
{
    	String code = new String();
		String tempVarName = getNextTempName();
    	code = code.concat(String.format("MusicPhrase %s = new MusicPhrase();\n", tempVarName));
    	for (String p : val_peek(1).listval) {
    		code = code.concat(String.format("%s.appendPhrase(%s);\n", tempVarName, p));
    	}
		upbeatVal res = new upbeatVal(code);
		res.sval = tempVarName;
		yyval = res;
    }
break;
case 147:
//#line 1971 "upbeat-a.yacc"
{
			Hashtable<String, String> musician_code = new Hashtable<String, String>();
			musician_code.put(val_peek(0).sval, val_peek(0).code);
    		yyval = new upbeatVal(1);
    		/* TODO: clean up the way we assign musician code*/
    		yyval.obj = musician_code;
    		/* ival indicates number of musicians*/
    	}
break;
case 148:
//#line 1980 "upbeat-a.yacc"
{
			Hashtable<String, String> musician_code = new Hashtable<String, String>();
			Hashtable<String, String> orig;
			Enumeration<String> k;
    		/* TODO: clean up the way we assign musician code*/
			orig = (Hashtable)val_peek(1).obj;
			k = orig.keys();
			while(k != null && k.hasMoreElements()) {
				String key = k.nextElement();
				if (key.equals(val_peek(0).sval)) {
					yyerror ("can't have more than one musician with the same name");
				}
				musician_code.put(key, orig.get(key));
			}
			musician_code.put(val_peek(0).sval, val_peek(0).code);
			yyval = new upbeatVal(1 + val_peek(1).ival);
			yyval.obj = musician_code;
			/* ival indicates number of musicians*/
    	}
break;
case 149:
//#line 2003 "upbeat-a.yacc"
{
    		SymbolTable t = new SymbolTable(current_symbol_table);
    		current_symbol_table = t;
    		current_symbol_table.inMusician = true;
    	}
break;
case 150:
//#line 2009 "upbeat-a.yacc"
{
    		String gen_code = new String();
    		
    		gen_code = gen_code.concat("package upbeat.sample;\n\n" +
    				"import upbeat.Musician;\n" +
    				"import upbeat.types.Cue;\n" +
    				"import upbeat.types.MusicPhrase;\n" +
    				"\n" +
    				"public class Musician_" + val_peek(4).code + " extends Musician {\n");
    		
    		if(val_peek(1).listval != null) {
    			for(String decl : val_peek(1).listval) {
    				gen_code = gen_code.concat(decl + "\n");
    			}
    		}
    		
    		try {
    		gen_code = gen_code.concat("	public Musician_" + val_peek(4).code + "() {\n" +
    				" 		// Call the Parent constructor.\n" +
    				"		super(" + getNextMusicianChannel() + ");\n" +
    				"		\n" + 
    				"		// Initializations.\n" +
    				"		try {\n" +
    				val_peek(1).sval +
    				"       } catch (Exception e) {\n" +
    				"			System.err.println(\"Did not correctly initialize Musician. \" + e +\n" +
    				"                  \"Music may sound incorrect.\");\n" +
    				"		}\n" +
    				"	}\n" +
    				val_peek(1).code +
    				"\n}\n");
    		} catch (Error e) {
    			yyerror("Error creating next musician: " + e.getMessage());
    		}
    		yyval = new upbeatVal(gen_code);
    		yyval.sval = val_peek(4).code; /* code has name of musician*/
        	current_symbol_table = current_symbol_table.parent;
    	}
break;
case 151:
//#line 2051 "upbeat-a.yacc"
{
    		String newCode = new String();
    		
	    	newCode = newCode.concat( "\n\n@Override\npublic void processCue(Cue cue) throws Exception {\n" );
	    	newCode = newCode.concat( val_peek(0).code );
	    	newCode = newCode.concat( "\n}" );
	    	
	    	yyval = new upbeatVal( newCode );
	    	yyval.sval = val_peek(1).code; /* statements*/
	    	yyval.listval = null; /* no declarations*/
    	}
break;
case 152:
//#line 2063 "upbeat-a.yacc"
{
	    	String newCode = new String();
	    	
	    	newCode = newCode.concat( "\n\n@Override\npublic void processCue(Cue cue) throws Exception {\n" );
	    	newCode = newCode.concat( val_peek(0).code );
	    	newCode = newCode.concat( "\n}" );
	    	
	    	yyval = new upbeatVal( newCode );
	    	yyval.sval = ""; /* no statements*/
	    	yyval.listval = new LinkedList<String>();
    		yyval.listval.add(val_peek(1).code);
	    }
break;
case 153:
//#line 2076 "upbeat-a.yacc"
{
	    	String newCode = new String();
	    	
/* A little hacky, but for musicians:
 * 1. The code field contains the entire processCue method.
 * 2. The sval field contains statements which go in the constructor
 * 3. The listval probably only contains one element which is the declarations; these go at the top of the class
 */

	    	newCode = newCode.concat( "\n\n@Override\npublic void processCue(Cue cue) throws Exception {\n" );
	    	newCode = newCode.concat( val_peek(0).code );
    		newCode = newCode.concat( "\n}" );
	    	
	    	yyval = new upbeatVal( newCode );
	    	yyval.sval = val_peek(1).code;
	    	yyval.listval = new LinkedList<String>();
    		yyval.listval.add(val_peek(2).code);
	    }
break;
case 154:
//#line 2095 "upbeat-a.yacc"
{
    		String newCode = new String();

    		/*In some cases, musicians will just want to play one thing the whole song, or just at the beginning of the song.  Might as well let them!*/
    		newCode = newCode.concat( "\n\n@Override\npublic void processCue(Cue cue) throws Exception {\n" );
    		/* No cue responses*/
			newCode = newCode.concat( "\n}" );
	    	
			yyval = new upbeatVal( newCode );
			yyval.sval = val_peek(0).code;
	    	yyval.listval = new LinkedList<String>();
			yyval.listval.add(val_peek(1).code);
	    }
break;
case 155:
//#line 2112 "upbeat-a.yacc"
{
    		yyval = new upbeatVal(val_peek(0).code);
    	}
break;
case 156:
//#line 2116 "upbeat-a.yacc"
{
    		String newCode = new String(val_peek(1).code + "\n" + val_peek(0).code + "\n");
    		yyval = new upbeatVal( newCode );
    	}
break;
case 157:
//#line 2124 "upbeat-a.yacc"
{
	    	SymbolTable t = new SymbolTable(current_symbol_table);
	    	current_symbol_table = t;
	    	current_symbol_table.inCueResponse = true;
	    }
break;
case 158:
//#line 2130 "upbeat-a.yacc"
{
    		String newCode = new String("if (cue.getName().equals(" + val_peek(2).sval + ") )\n" + val_peek(0).code + "\n");
    		yyval = new upbeatVal( newCode );
    		
    		current_symbol_table = current_symbol_table.parent;
    	}
break;
//#line 3666 "parser.java"
//########## END OF USER-SUPPLIED ACTIONS ##########
    }//switch
    //#### Now let's reduce... ####
    if (yydebug) debug("reduce");
    state_drop(yym);             //we just reduced yylen states
    yystate = state_peek(0);     //get new state
    val_drop(yym);               //corresponding value drop
    yym = yylhs[yyn];            //select next TERMINAL(on lhs)
    if (yystate == 0 && yym == 0)//done? 'rest' state and at first TERMINAL
      {
      if (yydebug) debug("After reduction, shifting from state 0 to state "+YYFINAL+"");
      yystate = YYFINAL;         //explicitly say we're done
      state_push(YYFINAL);       //and save it
      val_push(yyval);           //also save the semantic value of parsing
      if (yychar < 0)            //we want another character?
        {
        yychar = yylex();        //get next character
        if (yychar<0) yychar=0;  //clean, if necessary
        if (yydebug)
          yylexdebug(yystate,yychar);
        }
      if (yychar == 0)          //Good exit (if lex returns 0 ;-)
         break;                 //quit the loop--all DONE
      }//if yystate
    else                        //else not done yet
      {                         //get next state and push, for next yydefred[]
      yyn = yygindex[yym];      //find out where to go
      if ((yyn != 0) && (yyn += yystate) >= 0 &&
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
        yystate = yytable[yyn]; //get new state
      else
        yystate = yydgoto[yym]; //else go to new defred
      if (yydebug) debug("after reduction, shifting from state "+state_peek(0)+" to state "+yystate+"");
      state_push(yystate);     //going again, so push state & val...
      val_push(yyval);         //for next action
      }
    }//main loop
  return 0;//yyaccept!!
}
//## end of method parse() ######################################



//## run() --- for Thread #######################################
/**
 * A default run method, used for operating this parser
 * object in the background.  It is intended for extending Thread
 * or implementing Runnable.  Turn off with -Jnorun .
 */
public void run()
{
  yyparse();
}
//## end of method run() ########################################



//## Constructors ###############################################
//## The -Jnoconstruct option was used ##
//###############################################################



}
//################### END OF CLASS ##############################
